Skip to content

Instantly share code, notes, and snippets.

@rahmanusta
Created February 4, 2014 10:16
Show Gist options
  • Save rahmanusta/8801113 to your computer and use it in GitHub Desktop.
Save rahmanusta/8801113 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Basic Handlebars App" />
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<script id="book" type="text/x-handlebars-template">
<div>
<ul>
{{#each this}}
{{> row}}
{{/each}}
</ul>
</div>
</script>
<script id="row" type="text/x-handlebars-template">
<li>{{name}} - {{{author}}} - {{price}}</li>
</script>
</body>
</html>
var html = $("#book").html();
var row = $("#row").html();
var books = [
{
name:"Java ve Yazılım Tasarımı",
author:"<b>Altuğ Altıntaş</b>",
price:44
},
{
name:"<em>Java ve Yazılım Tasarımı</em>",
author:"Altuğ Altıntaş",
price:33
},{
name:"Java ve Yazılım Tasarımı",
author:"Altuğ Altıntaş",
price:34
}];
var compiled = Handlebars.compile(html);
Handlebars.registerPartial("row", row);
var result = compiled(books);
console.log(result);
$("body").append(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment