Created
August 26, 2014 21:26
-
-
Save jshaw/968d6e5408e32ef8e3f5 to your computer and use it in GitHub Desktop.
example javascript templates using underscore.js 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
<!--Example JS template--> | |
<script type="text/template" id="PastCommunityTemplate"> | |
<img class="pvs-cmy-img" src="<%= thumbnail %>" alt="<%= name %>"> | |
<h3 class="pvs-cmy-title"><%= name %></h3> | |
<h4 class="pvs-cmy-city">City: <%= city %></h4> | |
<p class="pvs-cmy-description"><%= summary %></p> | |
</script> |
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
// Test Object for template | |
this.object = { | |
thumbnail: 'asfasdfasdf.jpg', | |
name: 'jordan', | |
city: 'toronto', | |
summary: 'this is an example' | |
}; | |
// Gets what is inside of the JS template and treats is as html | |
// stores the js template function as this.tmpl | |
// replaces the template placeholders with what is passed in the object | |
this.tmpl = _.template($('#PastCommunityTemplate').html(); | |
this.$element.append(this.tmpl(this.object)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment