Tengine
Unifying APIs of various of template engines.
Installation
$ npm install tengine --save
Usage
const path = ;const tengine = ; const engine = ; engine; engineglobal = engine : 'tengine' ;eiginebase = path; engine;
Supported template engines
- doT (website) (example)
- dust (website) (example)
- eco
- ect (website)
- ejs (website) (example)
- haml
- haml-coffee
- handlebars (website)
- hogan (website)
- htmling
- jade (website) (example)
- jazz
- jqtpl
- liquid (website)
- lodash (website) (example)
- marko (website)
- mustache (example)
- nunjucks (website) (example)
- plates
- pug (website)
- ractive
- react
- slm
- swig-templates
- swig
- teacup
- templayed
- toffee
- twig
- underscore (website) (example)
- vash
- walrus (website)
- whiskers
APIs
tengine( string name[, object engine ] )
To initialize a template Engine
- name: the name of the template engine, see Supported template engines
- engine: to specify another template engine for replacing the default engine.
const engine = ;
const nunjucks = ;const engine = ;
tengine.support( string name )
to check if the template engine is supported in tengine.
- name: the name of the template engine
tengine.engines
An array of supported template engine's name.
engine.global
Global variables for templates.
const engine = ; engineglobal = title : 'global title' engine;
engine.base
The base directory of template files
const engine = ;enginebase = '/path/to/ejs/template/directory';engine;
engine.engine
The template engine instance.
engins.path( string name )
To get the full path of a template file in base direcotry.
- name: the file name of the template file.
engine.context( object data )
To get the context data which will includes the global variables if exists.
- the local context for compiling the template.
engine.configure( object options )
Configuring the template engines.
engine.render( string file, object context )
Rendering a template file.
- file: the template file name.
- context: the context for the template
engine.renderString( string str, object context )
Rendering template string.
- str: the template string
- context: the context for compiling