swig

A simple, powerful, and extendable templating engine for node.js and browsers, similar to Django, Jinja2, and Twig.

Use
Last updated 11 years ago by paularmstrong .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install swig 
SYNC missed versions from official npm registry.

Swig Build Status Dependency Status NPM version NPM Downloads

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

Need Help? Have Questions? Comments?

Installation

npm install swig

Documentation

All documentation can be viewed online on the Swig Website.

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

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

Copyright (c) 2010-2013 Paul Armstrong

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Current Tags

  • 1.4.2                                ...           latest (10 years ago)

53 Versions

  • 1.4.2 [deprecated]           ...           10 years ago
  • 1.4.1 [deprecated]           ...           10 years ago
  • 1.4.0 [deprecated]           ...           10 years ago
  • 1.3.2 [deprecated]           ...           11 years ago
  • 1.3.0 [deprecated]           ...           11 years ago
  • 1.2.2 [deprecated]           ...           11 years ago
  • 1.2.1 [deprecated]           ...           11 years ago
  • 1.2.0 [deprecated]           ...           11 years ago
  • 1.1.0 [deprecated]           ...           11 years ago
  • 1.0.0 [deprecated]           ...           11 years ago
  • 1.0.0-rc3                                ...           11 years ago
  • 1.0.0-rc2 [deprecated]           ...           11 years ago
  • 1.0.0-rc1 [deprecated]           ...           11 years ago
  • 1.0.0-pre3 [deprecated]           ...           11 years ago
  • 1.0.0-pre2 [deprecated]           ...           11 years ago
  • 1.0.0-pre1 [deprecated]           ...           11 years ago
  • 0.14.0 [deprecated]           ...           11 years ago
  • 0.13.5 [deprecated]           ...           12 years ago
  • 0.13.4 [deprecated]           ...           12 years ago
  • 0.13.3 [deprecated]           ...           12 years ago
  • 0.13.2 [deprecated]           ...           12 years ago
  • 0.13.1 [deprecated]           ...           12 years ago
  • 0.13.0 [deprecated]           ...           12 years ago
  • 0.12.1 [deprecated]           ...           12 years ago
  • 0.12.0 [deprecated]           ...           12 years ago
  • 0.11.2 [deprecated]           ...           13 years ago
  • 0.11.1 [deprecated]           ...           13 years ago
  • 0.11.0 [deprecated]           ...           13 years ago
  • 0.10.0 [deprecated]           ...           13 years ago
  • 0.9.4 [deprecated]           ...           13 years ago
  • 0.9.3 [deprecated]           ...           13 years ago
  • 0.9.2 [deprecated]           ...           13 years ago
  • 0.9.1 [deprecated]           ...           13 years ago
  • 0.9.0 [deprecated]           ...           13 years ago
  • 0.8.0 [deprecated]           ...           13 years ago
  • 0.7.0 [deprecated]           ...           13 years ago
  • 0.6.1 [deprecated]           ...           13 years ago
  • 0.6.0 [deprecated]           ...           13 years ago
  • 0.5.0 [deprecated]           ...           13 years ago
  • 0.4.0 [deprecated]           ...           13 years ago
  • 0.3.0 [deprecated]           ...           13 years ago
  • 0.2.3 [deprecated]           ...           13 years ago
  • 0.2.2 [deprecated]           ...           13 years ago
  • 0.2.1 [deprecated]           ...           13 years ago
  • 0.2.0 [deprecated]           ...           13 years ago
  • 0.1.9 [deprecated]           ...           13 years ago
  • 0.1.8 [deprecated]           ...           13 years ago
  • 0.1.7 [deprecated]           ...           13 years ago
  • 0.1.6 [deprecated]           ...           13 years ago
  • 0.1.5 [deprecated]           ...           13 years ago
  • 0.1.3 [deprecated]           ...           13 years ago
  • 0.1.2 [deprecated]           ...           13 years ago
  • 0.1.1 [deprecated]           ...           13 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (14)

© 2010 - cnpmjs.org x YWFE | Home | YWFE