Created
February 3, 2010 04:16
-
-
Save Marak/293318 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// simple variable replacement using {{}} and Mustache.to_html() | |
var str = Mustache.to_html('i like hats that are {{color}}', | |
{ | |
color : "blue" | |
} | |
); | |
console.log(str); // i like hats that are red | |
// replacing multiple variables | |
var str = Mustache.to_html('i like {{thing}} that are {{color}}', | |
{ | |
color : "blue", | |
thing : "dogs" | |
} | |
); | |
console.log(str); // i like dogs that are blue | |
// now we remember that second attribute accepts JSON, which means we can use ANYTHING JavaScript normally has access to. | |
var str = Mustache.to_html('i like {{thing}} that are {{color}} and {{stuff}} which is {{adjective}}', | |
{ | |
color : apiCall.getColor('dogs'), | |
thing : $('#animalSelect').val(), | |
stuff : function(){ | |
if(1=0){ | |
return 'hell'; | |
} | |
else{ | |
return 'poop'; | |
} | |
adjective : 'hard' | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like you're missing a closing bracket on that else statement.