2

I have a template with default Handlebars expansion {{thing}}.

For various nasty reasons I'd like to use it to render JSON, and so not to do the default HTML escaping that comes with {{.

I'd also like to use the template in an HTML context.

Can I set up a Handlebars.java instance with different default escaping behaviour?

Duncan McGregor
  • 17,665
  • 12
  • 64
  • 118

2 Answers2

1

You can configure Handlebars with various EscapingStrategys - in this case EscapingStrategy.JS does the trick.

Duncan McGregor
  • 17,665
  • 12
  • 64
  • 118
0

you can because you are using handlebars.java. By default, standard implementation of handlebars don't allow it.

as you can see on this issue, the code that you must use is this:

Handlebars hbs = new Handlebars()
    .startDelimiter("<%")
    .endDelimiter("%>");
TeoMatthew
  • 579
  • 2
  • 10
  • 19