Handlebar with one partial
Example of partial use
by gbos
HTML
<script id="default" type="text/x-handlebars-template">
<p>This is the top of the body content in the default.html file</p>
{{{content}}}
<p>This is the bottom of the body content in the default.html file</p>
</script>
<script id="index" type="text/x-handlebars-template">
{{include header }}
{{> default}}
{{include footer }}
</script>
<div id="resultPlaceholder">
</div>
CSS
p {color: red;}
.footer {font-size: smaller;}
JavaScript
$(document).ready(function () {
var defaultSource = $("#default").html();
var indexSource = $("#index").html();
Handlebars.registerPartial('default',defaultSource);
Handlebars.registerHelper('include', function(source) {
return new Handlebars.SafeString(source);
});
var template = Handlebars.compile(indexSource);
var context = { "content" : "<b>This is some other content</b>","header" : "<h1>This is a header</h1>", "footer" : "<div class='footer'>This is a footer</div>"} ;
var html = template(context);
$("#resultPlaceholder").html(html);
});