I'm quite new to programming and especially to handlebars. I have a div loaded with combination of jquery and handlebars in my html file. I have tabs on top of it. I want to reload all the content to a new one when there is a click on a tab. The content is similar (same structure) but labels, images and so on have to change. I tryed to use the partial in handlebars.js. Here is a sample code.
<script type="text/x-handlebars-template" id="all-handlebar">
{{#each tabs}}
<div id=tab{{@index}}>{{this.text}}</div>
{{/each}}
<div id="tab-content">{{> tabContentPartial}}
</script>
<script type="text/x-handlebars-template" id="tab-content-partial">
<div id="mycontent">
<div id="text">{{mycontent.text}}</div>
<div id="text">{{mycontent.image}}</div>
</div>
</script>
<script type="text/javascript">
source=$("#all-handlebar").html();
var template = Handlebars.compile(source);
Handlebars.registerPartial("tabContentPartial", $("#tab-content-partial").html())
var context = {
mycontent : {
text="something that has to change everytime I click on a different tab",
image="idem"
};
var html = template(context);
$("body").html(html);
</script>
It loads well the first time but when I click on the tab, I ask him to re-registerPartial the tab-content-partial script and it doesn't exist anymore because it has changed to HTML block right in my code. How can reuse and reload my partial script with new contents ?
Thank you very much !