getTemplate - pfaciana/latte-js GitHub Wiki

Latte.prototype.getTemplate(name)

Whenever there is {include} or {extends} tag in a template, Latte.prototype.getTemplate() method called and receives the tag's file parameter as an argument. The method must return the template's text.

The default implementation of getTemplate() throws an exception. So, it is up to a Latte user to override this method and provide template's text.

/* browser example */
Latte.prototype.getTemplate = function(id) {
    return document.getElementById(id).innerHTML;
}

/* Nodejs example: */
var fs = require('fs');

Latte.prototype.getTemplate = function(name) {
    return fs.readFileSync('path/to/templates/'+name, 'utf8');
}