I have an error page , which is a handlebar.js template. I need to load this template in the current page handlebar.js template. A typical include < file name > type, but could not found a way around in handlebar. Please advise me here .
Thanks.
Sounds like you're looking for a partial. A partial is a template fragment that you want to include in several other templates. You'd do something like this in your templates:
<script id="error" type="text/x-handlebars">
<!-- Error display stuff goes here -->
</script>
<script id="t" type="text/x-handlebars">
{{> error}}
</script>
Then register the partial:
Handlebars.registerPartial('error', $('#error').html());
Once that's done, you can use #t
as normal:
var t = Handlebars.compile($('#t').html());
var h = t({ ... });
Demo: http://jsfiddle.net/ambiguous/P2BK7/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With