I have the following code and want to set all my underscore templates to use mustache syntax. If I move the _.templateSetting outside the function, it doesn't work. How would I set this globally?
thx in advance
arc_eh.mb={
show_tree:function(){
// all i want to do is move this outside and set globally
// for all my underscore microtemplates
_.templateSettings = {
interpolate : /\{\{(.+?)\}\}/g
};
var template=_.template("hello {{ some }}");
var jt = { "some" : "more-something" };
//var final=template({ some : "say-something" });
var final=template(jt);
console.log(final);
update #1
So I've updated your fiddle with the problem I am having here: http://jsfiddle.net/vMHeq/1/
I AGREE that you fiddle works fine - I know this is a scope issue that I'm not familiar with. Any help appreciated.
_.templateSettingsoutside the function should work assuming of course thatunderscore.jsis loaded before you mess with_.templateSettings. PS: You should set all three regexes intemplateSettingsif you want to change the delimiters.