Is it possible to use JavaScript inside handlebars.js template

丶灬走出姿态 提交于 2019-12-01 14:45:22

问题


The description says it all. How to put a JavaScript script inside handlebars template.

I want to make a dynamic Paypal button for my website.

      <script type="text/x-mustache-template" id="product-item-thumbnail-template">
      <h2>{{title}}</h2>
      <p>{{message}}</p>
      <p><a class="btn" href="#">View details &raquo;</a></p>
      <p><script src="resources/js-frameworks/paypal-button.min.js?merchant=myemail@GMAIL.COM"
            data-button="buynow"
            data-name="My product"
            data-amount="1.00"></script></p>
</script>

But this produces an error because of the tag. it closes the template script and not the paypal script

Thanks


回答1:


Try breaking up the "/script" part:

<script ...><{{!}}/script>

That technique is similar to older hacks like

<script>document.write("<script>...<\/script>");</script>


来源:https://stackoverflow.com/questions/17369855/is-it-possible-to-use-javascript-inside-handlebars-js-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!