Can't pass helpers to Pug engine
max-block opened this issue · 2 comments
max-block commented
Here is a test file:
const Koa = require("koa")
const views = require("koa-views")
const app = new Koa()
app.use(
views(__dirname + "/views", {
extension: "pug",
options: {
helpers: {
uppercase: str => str.toUpperCase()
}
}
})
)
app.use(ctx => ctx.render("index", { name: "Name1" }))
app.listen(3000)
Template file views/index.pug is simple: h1= uppercase(name)
But Pug doesn't see this template:
$ DEBUG=koa-views node index
koa-views render `index.pug` with {"name":"Name1","helpers":{},"partials":{}} +0ms
TypeError: /Users/max7z/projects/test/t24__test__koa-views_pug/views/index.pug:1
> 1| h1= uppercase(name)
2|
uppercase is not a function
at eval (eval at wrap (/Users/max7z/projects/test/t24__test__koa-views_pug/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:6:57)
int64ago commented
helpers
is not the option of pug but handlebars
max-block commented
Is it possible to use helpers for pug with koa-views module?
It's possible to do it with koa-pug module, here is code sample:
import * as helpers from "./helpers"
const pug = new Pug({
app,
viewPath: path.join(__dirname, "../templates"),
helperPath: [helpers],
noCache: !IS_PRODUCTION
})