如果我将代码放在/ etc中,Handlebars.js将不会解析它。一旦它在外部,它就会正常工作。
<script id="entry-template" type="text/x-handlebars-template">
<div class="entry">
{{#each this}}
<h1>{{title.rendered}}</h1>
<div>{{content.rendered}}</div>
<img src="{{url}}" alt=""/>
{{/each}}
</div>
</script>我本以为
<img src="http://localhost/image.jpg" alt=""/>但产出如下:
<img src="{{url}}" alt=""/>其他一切似乎都正常。回路也是。
发布于 2019-06-19 14:41:46
使用
<script id="t" type="text/x-handlebars-template">
<img class="someClass" src="{{url}}">
</script>模板很少有效且格式正确,因此您需要防止浏览器试图将模板解释为HTML。通常的方法是将模板存储在具有非HTML类型的模板中:
或者使用三重括号
<img src="{{{your source}}}" alt={{{your alt}}} />
工具栏HTML-转义由{{表达式}}返回的值。如果你不想让车把转义一个值,那就用“三重藏”, {foo}}
来源:http://handlebarsjs.com/expressions.html
https://stackoverflow.com/questions/56669995
复制相似问题