Swig
A simple, powerful, and extendable JavaScript Template Engine.
Current Version: v1.4.2. Looking for an older version?
Super Quick Start
For a more in-depth intro, check out the Getting Started docs.
Install Swig
npm install swig --save
Create Your Template
<h1>{{ pagename|title }}</h1>
<ul>
{% for author in authors %}
<li{% if loop.first %} class="first"{% endif %}>
{{ author }}
</li>
{% endfor %}
</ul>
Render Your Template
var swig = require('swig');
swig.renderFile('/path/to/template.html', {
pagename: 'awesome people',
authors: ['Paul', 'Jim', 'Jane']
});
The End Result
<h1>Awesome People</h1>
<ul>
<li class="first">Paul</li>
<li>Jim</li>
<li>Jane</li>
</ul>
Features
- Available for node.js and major web browsers!
- Uses similar methodologies as Django, Jinja2, and Twig template engines.
- 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.
- Great code coverage.
Download For the Browser
Swig also works in all major browsers. Just download the following file and follow the Documentation.
Download v1.4.2
Development | Production (source map)