Nikhil Tikoo
Nikhil Tikoo

Reputation: 375

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.

Upvotes: 0

Views: 318

Answers (2)

ashok93
ashok93

Reputation: 103

I would suggest you to have a separate handlebar div for compilation purpose and use that compiled HTML to append in your appropriate div so that you don't override your handlebar code in HTML.

Upvotes: 1

Azamantes
Azamantes

Reputation: 1451

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.

Upvotes: 1

Related Questions