instance method Template#evaluate

View source on GitHub →

Template#evaluate(object) → String

Applies the template to object's data, producing a formatted string with symbols replaced by object's corresponding properties.

Examples
var hrefTemplate = new Template('/dir/showAll?lang=#{language}&categ=#{category}&lv=#{levels}');
var selection = {category: 'books' , language: 'en-US'};
 hrefTemplate.evaluate(selection);
// -> '/dir/showAll?lang=en-US&categ=books&lv='
 hrefTemplate.evaluate({language: 'jp', levels: 3, created: '10/12/2005'});
// -> '/dir/showAll?lang=jp&categ=&lv=3'
 hrefTemplate.evaluate({});
// -> '/dir/showAll?lang=&categ=&lv='
 hrefTemplate.evaluate(null);
// -> error !