Templet
npm install templet
A tiny templating engine for Node.
Usage
Templet does no caching or inline JavaScript evaluation (yet). Any ulterior responsibilities are left to you. It simply renders some template pseudo-HTML based on a mustache style {{
(open) and }}
(close) tags.
var templet = ;templet;
...or you can set the open/close tags yourself and try your luck with your existing templates:
templet;templet;
Using default templates
Templet comes with a base template which has two variables: title
and body
.
var page = templet.render(templet.TEMPLATES.BASE, {title:'My Title', body:'Greetings'});
Using http.ServerResponse.render
Templet also extends http.ServerResponse with render
method.
var base = templetTEMPLATESBASE;http;
Building an element jQuery-style
Templet has also methods for creating an element with a chainable interface, a la jQuery.
var el = templet id'mydiv' ;
You could use this generated element in some template:
var templet = ;var base = templetTEMPLATESBASE; var date = templettext; var page = templet;
You can also use appendChild
and appendTo
for building some HTML.
var date = templettext;var container = templet;
... but we should stop before replicating the entire DOM.
Use with caution
While basic string manipulation is fast enough, it's generally more efficient to use Node as an AJAX JSON service for dynamic content.