Skip to content

Instantly share code, notes, and snippets.

@mschwartz
Created April 17, 2012 01:04
Show Gist options
  • Save mschwartz/2402679 to your computer and use it in GitHub Desktop.
Save mschwartz/2402679 to your computer and use it in GitHub Desktop.
var smarty_cache = {}
function getCachedSmarty(key) {
// (key is whatever you use to lookup in the DB)
var template = smarty_cache[key];
if (!template) {
template = SQL.getDataRow(query_to_get_template);
var compiled = smart.compile(template);
template = {
template: template,
compiled: compiled
};
smarty_cache[key] = smarty_item;
}
return template.compiled;
}
function runSmarty(key, dict) {
var templateFn = getCachedSmarty(key);
return templateFn(dict); // this is the HTML output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment