Nikhil Tikoo Nikhil Tikoo - 2 months ago 25
Ajax Question

Stop rendering template in Handlebars

I have this small code that gets rendered the first time the page loads.

<div id="old-div">
<h2>{{description}}</h2>
<h2>{{example}}</h2>
</div>


Now the second time, an AJAX call happens and since first time the {{description}} and {{example}} are already filled, when i try to get the HTML of the template, instead of {{description}} and {{example}}, i get their values.

I don't want Handlebars to render the values to the expression when ajax call happens to that i can get the template and render new values.

Any help is appreciated.

Answer

Make a template, put it outside html <body> and use that to feed handlebars. You will be able to take it, feed handlebars and append to DOM with substituted values and retrieve the template itself (you can use <template> tag for it or <script> and add id attribute to reference it easily. That's how it's done on many websites.