Support for templates which output pure text instead of html

98 views
Skip to first unread message

Dhiraj

unread,
Oct 26, 2016, 7:42:53 PM10/26/16
to mustache.java
Hi,

We would like to use mustache as our templating engine, but for us we want to use it as Object-to-Text conversion instead of Object-to-HTML conversion. I see that currently some of the characters are escaped using HTML escape chars, which would not work in the context of Object-to-Text conversion.

Are there any plans of adding this support? Or this is not an intended usecase of mustache?

Regards,
Dhiraj

Dhiraj

unread,
Oct 26, 2016, 7:48:21 PM10/26/16
to mustache.java
I realized that this is already supported. 

Saw this in the documentation:

All variables are HTML escaped by default. If you want to return unescaped HTML, use the triple mustache: {{{name}}}.

You can also use & to unescape a variable: {{& name}}. This may be useful when changing delimiters (see "Set Delimiter" below).

Sam

unread,
Nov 2, 2016, 4:26:05 PM11/2/16
to mustache.java
For convenience, you could instead override the encode() call on DefaultMustacheFactory and just have it write the value to the writer directly rather than its default behavior that HTML encodes. This will let you use double curlies instead so you don't have to worry about making an inadvertent error.

Sam
Reply all
Reply to author
Forward
0 new messages