且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有可能在handlebars.js模板中使用JavaScript

更新时间:2023-10-26 11:52:34

尝试分解/ script部分:

 < script ...> ;&LT; {{}!} /脚本&GT; 

该技术类似于旧版hack,比如

 &LT;脚本&GT;文件撰写( &LT;脚本&GT; ...&LT; \ /脚本> 中);&LT; /脚本&GT; 


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

Try breaking up the "/script" part:

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

That technique is similar to older hacks like

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