Skip to content

Instantly share code, notes, and snippets.

@staticall
Created June 1, 2012 06:20
Show Gist options
  • Save staticall/2849494 to your computer and use it in GitHub Desktop.
Save staticall/2849494 to your computer and use it in GitHub Desktop.
Hogan.js local scope demo
var template = '{{#translate}}user-{{name}}{{/translate}}';
var template_compiled = Hogan.compile(template);
var data = {
"data": {
"1": {"name": "test"},
"2": {"name": "example"},
"3": {"name": "user"}
}
}
$.each(data.data, function(k, val){
val.translate = function(){
return function(text, scope){
text = $.trim(text);
if(typeof scope == 'object')
{
var tpl = Hogan.compile(text);
var res_text = tpl.render(scope);
text = res_text;
}
console.log('Translated element', text);
}
}
template_compiled.render(val);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment