ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

SafeString #34

Closed eden-lane closed 11 years ago

eden-lane commented 11 years ago

How can I use new Handlebars.SafeString() ?

ericf commented 11 years ago
var Handlebars = require('handlebars');
eden-lane commented 11 years ago

Thanks. I thought so.

ericf commented 11 years ago

We use this approach all the time for our helpers: https://github.com/yui/pure-site/blob/master/lib/helpers.js

eden-lane commented 11 years ago

I see. I thought that I shouldn't require handlebars for optimization reasons, because express3-handlebars already includes it. Sorry for my misunderstood, I'm still new in node.js

ericf commented 11 years ago

You can always use the reference from your Express Handlebars instance, whichever is easiest for you, the perf difference won't matter if you're doing the require() once, at top of a module.

eden-lane commented 11 years ago

Okay, thank you for the detailed answer and for your time !

antony commented 10 years ago

Seems that even if I use new Handlebars().SafeString it is still escaped. Did this work for you @edencore ?

antony commented 10 years ago

Seems that there is an issue here. SafeString only works if I use my helper as:

{{#marker x y z}}{{/marker}} and does not work if I use {{marker x y z}}

Should I raise this as an Issue?

eden-lane commented 10 years ago

@aiten it works well for me. Here is the example: http://jsbin.com/EpixuCA/2/edit (if I understand you correct). But I guess this question is for Handlebars repository, not for this one.

ghost commented 10 years ago

I might be late to the party here, but you can prevent handlebars from escaping the output by using the triple-stash, e.g. {{{marker x y z}}}

antony commented 10 years ago

If this works it is a winner.

On 12 February 2014 10:05, habhab notifications@github.com wrote:

I might be late to the party here, but you can prevent handlebars from escaping the output by using the triple-stash, e.g. {{{marker x y z}}}

— Reply to this email directly or view it on GitHubhttps://github.com/ericf/express3-handlebars/issues/34#issuecomment-34854544 .


ꜽ . antony jones . http://www.enzy.org

tuxsudo commented 10 years ago

Ditto on issue where Handlebars.SafeString only works with block helpers.

ericf commented 10 years ago

Handlebars uses an instanceof check to determine whether a string is a SafeString. There can be a problem with this if you have multiple copies of Handlebars in your app, i.e. express-handlebars is using a different version or copy than what's in your app's package.json.

To mitigate this, simply have express-handlebars use the same Handlebars instance you have in your apps — which is used in your custom helpers — by passing a reference to your copy Handlebars when you configure Express Handlebars.