Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 22 lines (15 sloc) 0.819 kb


You have 2 methods for creating a template object:

swig.fromString("Template string here");

Swig can be configured using the following:

    autoescape: true,   // Automatically escape all variable output. (Recommended true)
    encoding: 'utf8',   // Encoding for template files.
    root: '/views',     // The root directory to search for templates.
    filters: {},        // Optional custom filters.
    tags: {}            // Optional custom tags.

Both of them will give you a template object on which you call the render method passing it a map of context values.

var tmpl = swig.fromFile("path/to/template/file.html");
var renderedHtml = tmpl.render({ vars: 'to be inserted in template' });
Something went wrong with that request. Please try again.