Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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