Reputation: 163
At the start of all my pages, I have a bunch of links, namely jquery, bootstrap, and font-awesome. I decided to use handlebars to simplify this. (for the example, I only have 1 link to shorten the code)
<head>
{{links}}
</head>
My backend:
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);
});
However, this is what my head looks like:
<script src="https://code.jquery.com/jquery-1.11.1.js">
The special characters have been removed, and now it is a bunch of html characters. When chrome receives this, it errors and puts all this content into the body, leaving the head empty (without any links).
How do I prevent this?
Upvotes: 4
Views: 2070
Reputation: 163
I just read the docs. This can be avoided by using 3 curly braces, i.e.:
{{{links}}}
This lets handlebars know to not replace characters with special ones. Alternatively, one could use handlebar's "basic" mode, which is now deprecated. It has about the same functionality as the triple curly braces.
Upvotes: 8