Created
August 11, 2014 08:36
-
-
Save ynonp/5f129accb79d6f042f1e to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>index</title> | |
</head> | |
<body> | |
<p></p> | |
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.4/handlebars.min.js"></script> | |
<script type="text/template" id="template-all"> | |
{{#each people}} | |
<h1>{{name}}</h1> | |
<p>{{age}}</p> | |
{{/each}} | |
</script> | |
<script type="text/template" id="template-item"> | |
<h1>{{name}}</h1> | |
<p>{{age}}</p> | |
</script> | |
<script> | |
var data = [ | |
{ name: 'joe', age: 17, likes: ['skiing', 'driving'] }, | |
{ name: 'bob', age: 27, likes: ['reading'] }, | |
{ name: 'james', age: 19, likes: ['skating', 'the ocean'] }, | |
]; | |
var template_html = $('#template-all').html(); | |
var template = Handlebars.compile(template_html); | |
var result = template({ people: data }); | |
$('p').html(result); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment