Created
October 26, 2013 13:52
-
-
Save arbaaz/7169704 to your computer and use it in GitHub Desktop.
handlebar sample
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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>test</title> | |
</head> | |
<body> | |
<script type="text/x-handlebars-template" id='template'> | |
{{#each this}} | |
<h1>{{title}}</h1> | |
{{/each}} | |
</script> | |
<!-- keep the scripts in the scripts folder --> | |
<script type="text/javascript" src='scripts/jquery.js'></script> | |
<script type="text/javascript" src='scripts/Handlebars.js'></script> | |
<script type="text/javascript"> | |
var source=$('#template').html(); | |
console.log(source) | |
var template=Handlebars.compile(source); | |
console.log(template); | |
var context=[ { | |
title:'My second handlebar' | |
}, | |
{ | |
title:'This is the second' | |
}] | |
var html=template(context); | |
$('body').append(html); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment