-
-
Save milankorsos/1329750 to your computer and use it in GitHub Desktop.
underscore templates
This file contains hidden or 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 type="text/template" id="something-tmpl"> | |
<% for (var index = 0; index < items.length; index++) { %> | |
<% var item = items[index]; %> | |
<p><strong><%= item.username %></strong></p> | |
<% if (item.age) { %> <p>Age: <%= item.age %></p> <% } %> | |
<% if (item.sex) { %> <p>Sex: <%= item.sex %></p> <% } %> | |
<% if (item.location) { %> <p>Location: <%= item.location %></p> <% } %> | |
<% } %> | |
</script> |
This file contains hidden or 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
// initialization() | |
template = _.template($("#something-tmpl").html()); | |
// render() | |
var items = { | |
id: 1, | |
username: milan, | |
age: 25, | |
sex: "Guy", | |
location: "San Francisco" | |
}; | |
$(element).html(template({items : items })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment