Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A growing collection of tags and filters for Swig Templates.
Latest commit 77563c3 @jonschlinkert Merge pull request #2 from npeters/patch-1
add highlight.js
Failed to load latest commit information.
lib update templates, add some utils
tasks update templates, add some utils
.gitignore first commit
.jshintrc first commit
Gruntfile.js first commit
LICENSE-MIT first commit update related projects
index.js organize some code, add comments and additional attribution for Paul …
package.json add highlight.js

swig extensions

Tags, filters, and extensions for Swig, the most awesome template engine for node.js.

This project is based on (and complementary to) swig-extras, from @paularmstrong

Getting started

Use a filter:

var swig = require('swig');
var extensions = require('swig-extensions');

extensions.useFilter(swig, 'markdown');

Use a tag:

var swig = require('swig');
var extensions = require('swig-extensions');
var mySwig = new swig.Swig();

extensions.useTag(mySwig, 'markdown');

Available Filters

  • condense
  • markdown (using Marked)
  • prettify

Available Tags

  • markdown
  • prettify

Usage with Assemble

1. Install assemble-swig

npm install assemble-swig --save-dev

Once the assemble-swig engine has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:


2. Add swig to assemble

Specify swig as the current engine for processing templates:

assemble: {
  options: {
    engine: 'swig'

3. Add swig tags and filters

Specify the path or paths (optionally using minimatch patterns) to the helpers property in the Assemble options:

assemble: {
  options: {
    engine: 'swig',
    helpers: ['src/extensions/*.js']

load them as modules

For Assemble to find and register your custom tags and filters, you must export them either as objects or functions inside a module.exports object:

module.exports.register = function (swig, opts) {
  // filters and tags

Example of how to register multiple filters as properties of the filters object:

var filters = module.exports = {}; = function (input) {
  return input;

filters.two = function (input) {
  return input;

filters.three = function (input) {
  return input;

module.exports.register = function (swig, opts) {
  opts = opts || {};

  // filters.useFilter(swig, filters);
  for (var filter in filters) {
    if (filters.hasOwnProperty(filter)) {
      swig.setFilter(filter, filters[filter]);

Related projects

Copyright and license

Copyright (c) 2013 Jon Schlinkert, Brian Woodward, contributors Licensed under the MIT License (MIT)

Something went wrong with that request. Please try again.