Skip to content

Instantly share code, notes, and snippets.

@arbaaz
Created October 26, 2013 13:52
Show Gist options
  • Save arbaaz/7169704 to your computer and use it in GitHub Desktop.
Save arbaaz/7169704 to your computer and use it in GitHub Desktop.
handlebar sample
<!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