Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A page templating system for node.js based on John Resig's microtemplate function.
Branch: master
Pull request Compare This branch is even with greut:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


A templating system for node.js based on John Resig's JavaScript Micro-Templating.

Unlike that version (and Chad Etzel's) this one preserves whitespace allowing you to use blocks of (and inline) javascript and css in the page. It also has no problem with single quotes.


Templates are just files with special <% %> tags (like PHP or Ruby tags) which will be replaced with passed-in data. Templates can also contain javascript code to be expanded.

Example Template

 Hello, <%=name>.

Example Template with javascript

<% for (var i = 0; i < arr.length; i++) { %>
    The value of arr[<%=i%>] is <%=arr[i]%> <br/>
<% } %>


There are plenty of ways to use this:

Simple Usage with a String

sys.puts(template.create("Hello <%=word%>!", {word:"world"}));

Save the Template for Later

var t = template.create("Hello <%=word%>!");


template.create("Hello <%=word%>!", {word:kitty"}, function(t) {


  • Callbacks with non-processed templates.
  • Cache by filename (not string).
  • Auto-cache, reloads the cached file if a change is detected in the file. (This can be turned off on production.)

Other Info

You do not need to restart the node app to see the changes take effect. The reason is because it caches strings and not files. This has the downside of filling memory with useless templates until you restart the app. This should be fixed in a future version together with auto-cache.

Something went wrong with that request. Please try again.