在我所有页面的开头,我有一堆链接,即 jquery、bootstrap 和 font-awesome。我决定使用车把来简化这个过程。(例如,我只有1个链接来缩短代码)
<head>
{{links}}
</head>
Run Code Online (Sandbox Code Playgroud)
我的后端:
var templateData = {
links: '<script src="https://code.jquery.com/jquery-1.11.1.js"></script>'
};
fs.readFile(__dirname + "/front-end/blah.html", 'utf-8', function(error, source){
var temp = handlebars.compile(source)(templateData);
console.log(temp);
});
Run Code Online (Sandbox Code Playgroud)
然而,这就是我的头的样子:
<script src="https://code.jquery.com/jquery-1.11.1.js">
Run Code Online (Sandbox Code Playgroud)
特殊字符已经被去掉了,现在是一堆html字符了。当 chrome 收到此消息时,它会出错并将所有这些内容放入正文中,使头部为空(没有任何链接)。
我该如何防止这种情况?