Skip to content

Instantly share code, notes, and snippets.

@richtier
Created January 8, 2014 01:48
Show Gist options
  • Save richtier/8310324 to your computer and use it in GitHub Desktop.
Save richtier/8310324 to your computer and use it in GitHub Desktop.
quick and dirty jquery templating
// render playlist of songs
var template = '<li/><a>{{title}} by {{artist}}</a></li>';
context = [
{title: 'Killing Me Softly', artist: 'Roberta Flack'},
{title: 'Run Around Sue', artist: 'Dion'},
{title: 'Will You Still Love Me Tomorrow', artist: 'Shirelles'}
];
$('<ul/>', {text: 'songs'}).html(
$.map(context, function(item){
return $(template.replace(/{{(.*?)}}?/g, function($0, $1) {
return item[$1];
}))
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment