Swig

A Node.js and Browser-based JavaScript Template Engine

Swig

A Node.js and Browser-based JavaScript Template Engine


Get Started

Install Swig

npm install swig

Create Your Template

<h1>{{ pagename|title }}</h1>
<ul>
{% for author in authors %}
  <li{% if loop.first%} class="first"{% endif %}>
    {{ author }}
  </li>
{% else %}
  <li>There are no authors.</li>
{% endfor %}
</ul>

Render Your Template

var template  = require('swig');
var tmpl = template.compileFile('/path/to/template.html');
tmpl.render({
    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

  • Incredibly fast!
  • Available for node.js and major web browsers!
  • Extendable and customizable.
  • Express compatible.
  • Object-Oriented template inheritance.
  • Apply filters and transformations to output in your templates.
  • Automatically escapes all output.
  • Lots of iteration and conditionals supported.

Download For the Browser

Swig also works in all major browsers. Just download the following file and follow the Documentation.

Download

Fork me on GitHub