wjst
v1.0.1
Published
A simple, powerful, and extendable templating engine for node.js and browsers, similar to Django, Jinja2, and Twig.
Downloads
5
Maintainers
Readme
wjst
Wjst is an awesome, Django/Jinja-like template engine for node.js.
Features
- Available for node.js and major web browsers!
- Express compatible.
- Object-Oriented template inheritance.
- Apply filters and transformations to output in your templates.
- Automatically escapes all output for safe HTML rendering.
- Lots of iteration and conditionals supported.
- Robust without the bloat.
- Extendable and customizable. See Wjst-Extras for some examples.
- Great code coverage.
Need Help? Have Questions? Comments?
Installation
npm install wjst
Documentation
All documentation can be viewed online on the Wjst Website.
Basic Example
Template code index.html
<h1>{{ pagename|title }}</h1>
<ul>
{% for author in authors %}
<li{% if loop.first %} class="first"{% endif %}>{{ author }}</li>
{% endfor %}
</ul>
node.js code
const wjst = require('wjst');
const template = wjst.compileFile('./index.html');
const output = template({
pagename: 'awesome people',
authors: ['Den', 'Paul', 'Jane']
});
Output
<h1>Awesome People</h1>
<ul>
<li class="first">Den</li>
<li>Paul</li>
<li>Jane</li>
</ul>
For working example see examples/basic
How it works
Wjst reads template files and translates them into cached javascript functions. When we later render a template we call the evaluated function, passing a context object as an argument.