Created
October 4, 2013 06:50
-
-
Save DChinin/6821935 to your computer and use it in GitHub Desktop.
Backbone external templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rendered_html = render('mytemplate', {}); | |
function render(tmpl_name, tmpl_data) { | |
if ( !render.tmpl_cache ) { | |
render.tmpl_cache = {}; | |
} | |
if ( ! render.tmpl_cache[tmpl_name] ) { | |
var tmpl_dir = '/static/templates'; | |
var tmpl_url = tmpl_dir + '/' + tmpl_name + '.html'; | |
var tmpl_string; | |
$.ajax({ | |
url: tmpl_url, | |
method: 'GET', | |
async: false, | |
success: function(data) { | |
tmpl_string = data; | |
} | |
}); | |
render.tmpl_cache[tmpl_name] = _.template(tmpl_string); | |
} | |
return render.tmpl_cache[tmpl_name](tmpl_data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment