Search code examples
javascriptdjangonode.jsdjango-templatesswig-template

SWIG template widhout node - it is possible to use it as standalone js library?


There are some great js template engine for Django programmers: http://paularmstrong.github.io/swig/

But it is available in npn package for node.js. And render method require path to file:

swig.renderFile('/path/to/template.html', {
    pagename: 'awesome people',
    authors: ['Paul', 'Jim', 'Jane']
});

It is posible use it like others js/jquery librariers and render templates from string?


Solution

  • Yes, you can just use the render(source, options) method.

    var output = swig.render('{{ tacos }}', {
        locals: {
            tacos: 'Tacos!!!!'
        }
    });
    

    Unless you mean you want to run it in the browser, then take a look at the documentation.