Skip to content

Instantly share code, notes, and snippets.

@Marak
Created February 3, 2010 04:16
Show Gist options
  • Save Marak/293318 to your computer and use it in GitHub Desktop.
Save Marak/293318 to your computer and use it in GitHub Desktop.
// 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'
}
);
@colemickens
Copy link

It looks like you're missing a closing bracket on that else statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment