简体   繁体   中英

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.

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.

我建议您为编译目的使用一个单独的车把div ,并使用编译后的HTML附加到适当的div以免覆盖HTML中的车把代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM