Skip to content
JavaScript C++ C Shell
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


nTPL project: simple, fast and powerfull templates for node.js (

It's easy to learn - start now! Now comes with support of Express.js!

It's fast:

Mustache saids that running complex.html example gives following results: Mu - 40 secs (benchmarks/million_complex.js)

On my PC - running nTPL's: nTPL - 2 secs (benchmarks/million_complex.js)

Feel the difference?

Some features:

  • nTPL have native parser written on C++, so templates are compiled very fast.

  • nTPL have many optimizations in template rendering process.

  • nTPL uses buffers

  • nTPL is extendable (nTPL.modificators)

  • nTPL can reload template on file change (watch: true)


npm install nTPL

Manual installation instructions:

curl | sh or if it dies “Permission Denied” or EACCESS error curl | sudo sh

Advanced installation instructions:

git clone cd nTPL make make install make test

Basic examples:

nTPL(“1 + 1 = {%= 1+1 %}”)(); nTPL({ template : “1 + 1 = {%= 1+1 %}” })(); nTPL(“filename.tpl”)(); // 1 + 1 = 2 nTPL({ template : “Hello {%= a %}!”, args: [“a”] })({a: 'World'}); // >> Hello World! nTPL({ template: “Hello {%each a%}{%= this %}, {%/each%}world!”, args: [“a”] })({a: ['Andy','Alex']}); // >> Hello Andy, Alex, World! nTPL({ template: “{%if godmode%}My Lord!{%else%}Who are you?{%/if%}”, args: [“godmode”] })({godmode: true}); // >> My Lord! var $ = require(“nTPL”); $.parse(“It also works!”)(); // >> It also works!

Medium examples:

nTPL(“foo {* text here won't be compiled or printed *} bar”)(); // >> foo bar nTPL(“{%each [1,2,3] %} ”{%= this %}“ {%/each%}?”)(); // >> “1” “2” “3” nTPL(“{%catch var a %}What's up, dude?{%/catch%}{%= a.substr(0,9) %}?”)(); // >> What's up? nTPL({ template: “filename.tpl”, callback: function (tpl) { console.log(tpl()); } }); // Will load “filename.tpl” in async mode

Harder examples:

nTPL({ template: “<button>{%= value%}</button>”, args: [“value”], name: “input” }); nTPL(“input”)({value:'Hello world!'}); // >> Button with text “Hello world!” nTPL({ template: “filename.tpl”, callback: function (tpl) { console.log(tpl()); }, watch: true }); // Will load “filename.tpl” in async mode // And watch for file changes (template will be refreshed) // P.S. Also available in a sync mode

Block module

require(“nTPL.block”); nTPL({ template: “Hello, {%block 'username'%}{%/block%}!{%= message %}”, args: [“message”], name: “block-test” }); nTPL(“{%extends 'block-test', {message: ”How do you do?“}%}{%block 'username'%}Admin{%/block%}”)(); // >> Hello, Admin!How do you do?

Set modificators

Use “set” modificator to setup options inside template


“set.html” {%set name first template %} {%set args a1, a2, a3 %} {%set some 123 %} {%set 1,2,3 %} {%= a1 %} {%= a2 %} {%= a3 %}

Template generated from this file will have 'first template' name and can get 'a1', 'a2', 'a3' as arguments

var tpl = nTPL(“set.html”); nTPL(“first template”)({a1:1,a2:2,a3:3}); tpl.options; // {name: “first template”, args: [“a1”, “a2”, “a3”], some: “123”, foo : { bar: [“1”,“2”,“3”] } }

More info:

You can't setup any other options now. Only 'name' and 'args' are allowed. But if you generated template with “watch=true” and then change {%set … %} in template - 'name' and 'args' will be refreshed!

Something went wrong with that request. Please try again.