Skip to content

Instantly share code, notes, and snippets.

@nzifnab
Forked from tosh/jammit-jquery-tmpl.coffee
Created May 7, 2011 02:23
Show Gist options
  • Save nzifnab/960135 to your computer and use it in GitHub Desktop.
Save nzifnab/960135 to your computer and use it in GitHub Desktop.
jquery tmpl templating function for use with jammit
// It's more advisable to store the compiled version of the jQuery template in JST,
// And then use a separate function that renders on a per-use basis from that pre-compiled template.
function jqueryCacheTemplate(templateString){
return $.template(null, templateString);
}
function jqueryTemplate(name){
return $.tmpl(JST[name], arguments[0], arguments[1]);
}
// And then, in assets.yml, you can set "template_function" to "jqueryCacheTemplate"
// And to use a template, instead of JST['my_template](data), you should use jqueryTemplate('my_template', data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment