Reusing templates in handlebars
javascript, template-engine
Solution
That should be pretty easy using partials, and here is a pretty good tutorial.
Essentially though you just need to define the partial
Handlebars.registerPartial("template-2", $("#template-2").html());
And then utilize it
<script id="entry-template" type="text/x-handlebars-template">
<div>{{name}}</div>
{{> template-2}}
</script>
Problem
I am new to JS templating and Handlebars I have a nested JSON structure, often each parent node is a new object / has different structure so recursion is not the solution I think. My question is Is it possible to call another template from a template in Handlebars? My background is XSLT Example: ``` <script id="entry-template" type="text/x-handlebars-template"> <div>{{name}}</div> .. call template-2 </script> <script id="template-2" type="text/x-handlebars-template"> <div>{{name2}}</div> .. call template-3 </script> <script id="template-3" type="text/x-handlebars-template"> <div>{{name3}}</div> </script> ``` .. and so on Anyone who has some advice? Best regards, Bob