Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created August 11, 2014 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ynonp/5f129accb79d6f042f1e to your computer and use it in GitHub Desktop.
Save ynonp/5f129accb79d6f042f1e to your computer and use it in GitHub Desktop.
<!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