Skip to content

Instantly share code, notes, and snippets.

@TechnotronicOz
Created March 19, 2014 14:10
Show Gist options
  • Select an option

  • Save TechnotronicOz/9642403 to your computer and use it in GitHub Desktop.

Select an option

Save TechnotronicOz/9642403 to your computer and use it in GitHub Desktop.
//simple example of using lodash/underscore's template method
// update lodash/underscore to use mustache-style interpolations instead of erb
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g
};
// set the template
var template = _.template('<h1>{{title}}</h1><p>{{copy}}</p>');
// the object that will be passed to the template
var contentObj = {
title: 'The title to be inserted',
copy: 'The copy to be inserted'
}
// add to dom
$('.container').html(template(contentObj));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment