Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

nTPL

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 almost 9 years ago
Repo Created about 9 years ago
Repo Last Updated about 2 years ago
Size 1.76 MB
Homepage http://wiki.githu...
Organization / Authorindutny
Contributors1
Page Updated
Do you use nTPL? Leave a review!
View open issues (3)
View nTPL activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

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 %}")();
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

var ntpl = require("ntpl").plugins("ntpl.block").ntpl;

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 4 years Does Ntpl supports other competitors features?
  • almost 9 years Express.js with layout
  • almost 9 years RFE: debug=true flag
nTPL list of languages used
Other projects in JavaScript