var welcome_user = new Template('#{welcome} #{name}!!');
welcome_user.parse({ welcome: "Hello", name: "John" });
//returns "Hello John!!"
welcome_user.parse({ welcome: "Hola", name: "Peter" });
//returns "Hola Peter!!"
You can user your own modifier
method to cutomize the values.
An example, localizing the values with custom modifier
,
var locale = {
en: {
welcome: 'Hello'
},
fr: {
welcome: 'Bonjour'
}
};
var current_locale = 'en';
var welcome_user = new Template('#{welcome} #{name}!!');
welcome_user.modifier = function (match, key) {
return locale[current_locale][key] || this[key];
}
welcome_user.parse({ name: "Michelle" });
//returns "Hello Michelle!!"
current_locale = 'fr';
welcome_user.parse({ name: "Marie" })
//returns "Bonjour Marie!!"