A Node.js and Browser-based JavaScript Template Engine


A simple, powerful, and extendable JavaScript Template Engine.

Current Version: v2.0.0. 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>
{% for author in authors %}
  <li{% if loop.first %} class="first"{% endif %}>
    {{ author }}
{% endfor %}

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>
  <li class="first">Paul</li>


  • 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 v2.0.0

Development | Production (source map)