Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including template-js with all npm packages installed. Try it out:

var templateJs = require("template-js")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

template-js v1.0.10

Simple and Easy Templates for Node.js

template-js

Simple and Easy Javascript Templates for Node.js.

Installation

npm install template-js

Usage

// Your code

var Template = require('template-js')

var my_template = new Template('my.tmpl', {text: "<h1>Hello World</h1>"})

console(my_template.toString())
// my.tmpl

This is a template.

It can render context items: {{ text }}

It can execute javascript:
{% for (i=0;i<3;i++) { %}
Number {{ i }}: {{ text }}
{% } %}

It can escape strings:
{- text -}

It can include subtemplates:

{{ include('sub.tmpl') }}

Enjoy!

Output:

This is a template.

It can render context items: <h1>Hello World</h1>

It can execute javascript:

Number 0: <h1>Hello World</h1>

Number 1: <h1>Hello World</h1>

Number 2: <h1>Hello World</h1>


It can escape strings:
&lt;h1&gt;Hello World&lt;/h1&gt;

It can include subtemplates:

Included templates are cool!

Enjoy!
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free