Created
January 8, 2014 01:48
-
-
Save richtier/8310324 to your computer and use it in GitHub Desktop.
quick and dirty jquery templating
This file contains 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
// 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