swiger

0.0.2 • Public • Published

Swig Build Status Dependency Status NPM version NPM Downloads

Swig is an awesome, Django/Jinja-like template engine for node.js.

Thanks

Thank Paul and previous swig collabs for their hard and excellent work!

Paul Armstrong has stepped down as the primary swig maintainer.

Documentation

All documentation can be viewed online on the Swiger Website.

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 Swig-Extras for some examples.
  • Great code coverage.

Installation

npm install swiger

Basic Example

Template code

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

node.js code

var swig  = require('swig');
var template = swig.compileFile('/absolute/path/to/template.html');
var output = template({
    pagename: 'awesome people',
    authors: ['Paul', 'Jim', 'Jane']
});

Output

<h1>Awesome People</h1>
<ul>
    <li class="first">Paul</li>
    <li>Jim</li>
    <li>Jane</li>
</ul>

For working example see examples/basic

Need Help? Have Questions? Comments?

How it works

Swig 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.

License

MIT

Package Sidebar

Install

npm i swiger

Weekly Downloads

9

Version

0.0.2

License

MIT

Last publish

Collaborators

  • thunf