JavaScript templating from Twitter.

View on Github

Getting started

Hogan.js is a 3.4k 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/3.0.1/hogan-3.0.1.js"></script>


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.


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.


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.


Hulk is Hogan's command line utility. Use it to easily compile your templates as js files.

Hulk supports the * wilcard (even on windows) and allows you to target specific file extensions as well.