hogan-cached

3.0.0 • Public • Published

hogan-cached

Express.js view engine that renders Mustache with Hogan.js and caches compiled templates for more speed

NPM

  • Designed for Express 4.x
  • Cache: Compiles once. Renders faster.
  • Partials support
  • Lambda support
  • All of mustache(5) features

Examples

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);

Partials

// 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>

Lambda

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}}

Options

Customizable Hogan.js options

// Sets the delimiters to <% %> instead of {{ }}
app.set('hogan options', {delimiters: '<% %>'});
 

Cache

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);

More examples?

Check out test/test.js

Package Sidebar

Install

npm i hogan-cached

Weekly Downloads

2

Version

3.0.0

License

LGPL-2.0

Last publish

Collaborators

  • guichaguri
  • rogerta