README
express-dustjs
A Dustjs middleware for Express.
Installation
npm install express-dustjs
Usage
var express = require('express')
var app = express()
var path = require('path')
var dust = require('express-dustjs')
// Dustjs settings
dust._.optimizers.format = function (ctx, node) {
return node
}
// Define custom Dustjs helper
dust._.helpers.demo = function (chk, ctx, bodies, params) {
return chk.w('demo')
}
// Use Dustjs as Express view engine
app.engine('dust', dust.engine({
// Use dustjs-helpers
useHelpers: true
}))
app.set('view engine', 'dust')
app.set('views', path.resolve(__dirname, './views'))
app.get('/', function (req, res) {
// Render template with locals
res.render('index', {
title: 'Hello world',
name: 'Joe',
sentence: 'The quick brown fox jumps over the lazy dog',
number: req.query.number || 0
})
})
API
_
A reference of Dustjs instance. You can use it to change Dustjs settings or define helper / filter.
dust._.helpers.demo = demo
bind()
By default, express-dustjs
will use dustjs-linkedin (^2.5.1) to render template, if you want to use another version of dustjs
, do like this:
var dust = require('express-dustjs')
dust.bind(otherDust)
// Equals to
var dust = require('express-dustjs')(otherDust)
engine()
Create a tempalte engine middleware for Express.
app.engine('dust', dust.engine({
useHelpers: true
}))
app.set('view engine', 'dust')
Options:
useHelpers
: iftrue
, will load [dustjs-helpers
] (^1.5.0).
Compatibility
- Node
>= 0.10
- Express
>= 4.10
.
Contributors
Via GitHub