Express.js view engine that renders Mustache with Hogan.js and caches compiled templates for more speed
- Designed for Express 4.x
- Cache: Compiles once. Renders faster.
- Partials support
- Lambda support
- All of mustache(5) features
var express = require('express');
var app = express();
app.engine('html', require('hogan-cached'));
app.set('view engine', 'html');
app.get('/', function(req, res) {
res.render('index', {
title: 'Hello World!'
});
});
app.listen(80);
// Register globally
app.set('partials', {header: 'path/to/header'});
app.get('/', function(req, res) {
res.render('index', {
title: 'Hello World!',
// Register only for this render
partials: {
content: 'path/to/content'
}
});
});
{{> header}}
<div id="content">
{{> content}}
</div>
app.get('/', function(req, res) {
res.render('lambda', {
// Use a function
center: function() {
return function(text) {
return '<div style="text-align: center;">' + text + '</div>';
};
},
// Or just a condition
logged_in: false
});
});
{{#center}}
I'm centered!
{{/center}}
{{#logged_in}}
<strong>You are logged in!</strong>
{{/logged_in}}
Customizable Hogan.js options
// Sets the delimiters to <% %> instead of {{ }}
app.set('hogan options', {delimiters: '<% %>'});
You can clear the cache anytime with clearCache
var engine = require('hogan-cached');
app.engine('html', engine);
app.set('view engine', 'html');
// ...
engine.clearCache();
You can also disable the cache for dev environment
app.set('hogan cache', false);
Check out test/test.js