Want to take your software engineering career to the next level? Join the mailing list for career tips & advice Click here


node.js Templating system

Subscribe to updates I use nTPL

Statistics on nTPL

Number of watchers on Github 23
Number of open issues 3
Average time to close an issue 1 day
Main language JavaScript
Open pull requests 0+
Closed pull requests 0+
Last commit over 9 years ago
Repo Created about 10 years ago
Repo Last Updated almost 3 years ago
Size 1.76 MB
Homepage http://wiki.githu...
Organization / Authorindutny
Page Updated
Do you use nTPL? Leave a review!
View open issues (3)
View nTPL activity
View on github
Book a Mock Interview With Me (Silicon Valley Engineering Leader, 100s of interviews conducted)
Software engineers: It's time to get promoted. Starting NOW! Subscribe to my mailing list and I will equip you with tools, tips and actionable advice to grow in your career.
Evaluating nTPL for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

==ntpl project: simple, fast and powerfull templates for node.js (http://github.com/donnerjack13589/ntpl). 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 - 6 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)

==Installation: npm install ntpl

==Manual installation instructions: curl http://github.com/donnerjack13589/ntpl/raw/master/install.sh | sh or if it dies Permission Denied or EACCESS error curl http://github.com/donnerjack13589/ntpl/raw/master/install.sh | sudo sh

==Advanced installation instructions:
git clone git@github.com:donnerjack13589/ntpl.git cd ntpl make all make test

==Basic examples: var ntpl = require(ntpl).plugins(ntpl.block, ntpl.filter).ntpl;

ntpl("1 + 1 = {%= 1+1 %}")();
    template : "1 + 1 = {%= 1+1 %}"
// 1 + 1 = 2

    template : "Hello {%= a %}!",
    args: ["a"]
})({a: 'World'});
// >> Hello World!

    template: "Hello {%each a%}{%= this %}, {%/each%}world!",
    args: ["a"]
})({a: ['Andy','Alex']});
// >>  Hello Andy, Alex, World!

    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?

    template: "filename.tpl",
    callback: function (tpl) {
// Will load "filename.tpl" in async mode

==Harder examples:

    template: "<button>{%= value%}</button>",
    args: ["value"],
    name: "input"
ntpl("input")({value:'Hello world!'});
// >> Button with text "Hello world!"

    template: "filename.tpl",
    callback: function (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

var ntpl = require("ntpl").plugins("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

===Examples: set.html {%set name first template %} {%set args a1, a2, a3 %} {%set some 123 %} {%set foo.bar 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!

nTPL open issues Ask a question     (View All Issues)
  • over 5 years Does Ntpl supports other competitors features?
  • over 9 years Express.js with layout
  • over 9 years RFE: debug=true flag
nTPL list of languages used
Other projects in JavaScript