Hogan.js

JavaScript templating from Twitter.

View on Github

Getting started

Hogan.js is a 2.5k JS templating engine developed at Twitter. Use it as a part of your asset packager to compile templates ahead of time or include it in your browser to handle dynamic templates.

If you're developing with Node.js, just use NPM to add the Hogan package.

$ npm install hogan.js

Alternatively, drop hogan.js in your browser by adding the following script.

<script src="http://twitter.github.com/hogan.js/builds/{{version}}/hogan.js"></script>

Templates

Hogan.js was developed against the mustache test suite, so everything that holds true for templates as specified here, is also the case for hogan.js.

That means you get variables, sections, lambdas, partials, filters, and everything else you've come to expect from mustache templating - only much, much faster.

Compiling

Use hogan.compile() to precompile your templates into vanilla JS.

It's best to serve your templates precompiled whenever you can (rather than the raw templates), as parsing is the most time consuming operation.

Rendering

Once compiled, call the render() method with a context and optional partials object.

If supplying partials, you can compile them ahead of time, or pass string templates.