Introduction
Dustjs is a JS template, the earliest by the personal development and maintenance, later by the Linkin took over, the development of more rapid, to tell the Truth JS template This block has a lot of choices, are very excellent, and PayPal's choice, eventually I use Dustjs as my preferred template language. Dustjs Chinese documents very few, so in the domestic use is not a lot, here are a few blog post has a basic introduction to DUSTJS Grammar dust.js syntax Introduction (i), dust.js syntax Introduction (ii), Dust.js syntax Introduction (three)
express4.0 Default template engine is Jade,jade just started to feel like Python, has a strict syntax format, convenient for programmers to develop good coding habits, but in the actual use will find this coercion, in the template-side writing logic language, Especially in the case of nesting judgment, there will be some insurmountable problems, and its performance problems have been criticized by others. Of course you can also Ejs or other templates, this is not the point I want to elaborate.
Realize
If the Express project is off-the-shelf or after using express-genarate to generate a basic structure, package.json dependencies Add three dependencies to the file.
"Dustjs-helpers": "~1.3.0", "Dustjs-linkedin": "~2.4.2", "Adaro": "^0.1.5"
The dustjs-linkedin Dustjs template itself, which dustjs-helpers is an extension of some templates, is very useful in the official documentation of DUSTJS, and you can add your own helper methods. While Adaro is a Dustjs rendering class library provided by PayPal, it is easy to switch between multiple template engines, and PayPal's Express-based web framework KRAKENJS uses Adaro as a template management tool.
Then add the usage of the template to the app's entry code
var Dustjs = require (' Adaro '); var app = Express ();//Register App.engine ("Dust", Dustjs.dust ({cache:false}));//view engine SE Tupapp.set (' Views ', Path.join (__dirname, ' views ')); App.set (' View engine ', ' dust ');
Then use the view file to add the. Dust suffix under the views directory.
If you write your own helper, then you need to manually require the portal file.
Using the Dustjs template engine in Expressjs4.0