Created
May 5, 2012 08:29
-
-
Save SiTaggart/2600935 to your computer and use it in GitHub Desktop.
Underscore to moustache syntax and useage
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
<script> | |
//set underscore to have {{ }} terms | |
_.templateSettings = { | |
interpolate : /\{\{(.+?)\}\}/g, | |
evaluate: /\{%([\s\S]+?)%\}/g | |
}; | |
//set variables | |
var _subscriptionChannels = _.template($('#template').html()), | |
templateData = { | |
Owner: 'Channel 10', | |
channels: [ | |
{ | |
Name: 'test channel', | |
ImageUrl: '/path/to/image.jpg' | |
}, | |
{ | |
Name: 'test channel 2', | |
ImageUrl: '/path/to/image.jpg' | |
} | |
] | |
}, | |
content = _subscriptionChannels(templateData); | |
//append compiled content | |
$('body').append(content); | |
</script> | |
<script type="text/template" id="template"> | |
<ul class="om-available-channels-list om-available-channels-list-short"> | |
<li class="om-available-channels-heading"> | |
<h5>{{ Owner }}</h5> | |
</li> | |
{% _.each(channels, function(channel){ %} | |
<li> | |
<img height="34" alt="{{ channel.Name }}" src="{{ channel.ImageUrl }}"> | |
</li> | |
{% }); %} | |
</ul> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment