express에서 핸들바로 개발하는 중.. ‘partial’ 기능을 사용하려는데 에러가 잡히지가 않았다. 스택오버플로우에서 알려준대로 해도 설정이 안먹히는 것 같았다. helper를 정의했는데도 Missing helper 에러가 뜨고 partial folder 경로를 정해줬는데도 자꾸 못 찾아왔다. 드디어 알아낸 문제의 원인은 hbs과 express-handlebars 이 두개의 view engine 을 혼용하고 있어서.. 였다. 여러 코드 솔루션을 보다보니 저 두 개가 다른건줄 모르고 섞어서 쓰고있었다. . 하나로 사용하는 엔진이 달라지다니.. 조심해야겠다.
import { create } from"express-handlebars"; const hbs = create({ extname: ".hbs", // Specify helpers which are only registered on this instance. helpers: { if_equal: function (a, b, opts) { if (a == b) { return opts.fn(this); } else { return opts.inverse(this); } }, }, // Specify partials directory partialsDir: path.join(__dirname, "../views/partials"), });
//The following example sets up an Express app to use //.hbs as the file extension for views: app.engine(".hbs", hbs); app.set("view engine", ".hbs"); //with dot!!!