twitter / hogan.js

A compiler for the Mustache templating language
http://twitter.github.io/hogan.js
Apache License 2.0
5.14k stars 431 forks source link

Unescaped text does not work in conjunction with delimiters option #173

Closed bcronin closed 10 years ago

bcronin commented 10 years ago

If a template is compiled with custom delimiters then unescaped HTML does not expand correctly.

E.g. the template is compiled with Hogan.compile(rawText, { delimiters : "<% %>" });, then <%{ my_variable }%> does not expand correctly.

The best workaround I've found is a verbose temporary re-override of the delimiters:

<%={{ }}=%>{{{ my_variable }}}{{=<% %>=}}
sayrer commented 10 years ago

don't add the closing bracket, or use the "&" synonym for triple-stache.

var context = {myvariable: "|<>|_"} var rawText = "<%{ myvariable %>" var template = Hogan.compile(rawText, { delimiters : "<% %>" }); template.render(context) '|<>|_' var rawText = "<%& myvariable %>" template = Hogan.compile(rawText, { delimiters : "<% %>" }); template.render(context) '|<>|_'