请,我对把手模板还比较陌生,我的把手模板仅适用于html文件,但是当我尝试呈现包含把手模板的页面时,我会遇到各种错误。
<script id="quote-template" type="text/x-handlebars-template">
<h3>Favorite {{name}} Quotes</h3>
<ol>
{{#each quotes}}
<li>{{quote}}</li>
{{/each}}
</ol>
{{{ michaelBio }}} <br/><br /> {{ makeLink "Michael Museum" "http://google.com" }}
</script>
<script type="text/javascript">
var quoteInfo = document.querySelector("#quote-template").innerHTML;
var template = Handlebars.compile(quoteInfo);
Handlebars.registerHelper("makeLink", (text, url) => {
text = Handlebars.Utils.escapeExpression(text);
url = Handlebars.Utils.escapeExpression(url);
var theLink = '<a href="' + url + '">' + text + '</a>';
return new Handlebars.SafeString(theLink);
});
var quoteData = template({
name: "Michael",
quotes: [{
quote: "Jesus is the King of kings"
}, {
quote: "Lamb of God"
}, {
quote: "The saviour of my soul"
}],
michaelBio: '<i>The son of the lion of the tribe of Judah</i>'
})
document.querySelector("#quote_data").innerHTML += quoteData;
</script>