Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handlebars is removing special characters

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:

&lt;script src&#x3D;&quot;https://code.jquery.com/jquery-1.11.1.js&quot;&gt;

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?

like image 853
Jojo Mako Avatar asked Oct 16 '25 02:10

Jojo Mako


1 Answers

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.

like image 159
Jojo Mako Avatar answered Oct 18 '25 20:10

Jojo Mako



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!