简体   繁体   中英

mustache js : is it possible to have mustache render html that is within the json object being passed in?

Is it possible to have mustache render html that is within the json object being passed in? Here is an example :

json object

{
    message : "Hello World! <em>How are you?</em>"
}

template

<p>{{message}}</p>

current output

Hello World! <em>How are you?</em>

desired output

Hello World! How are you?

Use the 'triple mustache', ie {{{message}}} instead of {{message}} . The extra brace overrides Mustache.js' default escaping.

If your mustache.js is relatively recent, you should also be able to use & to unescape a value, ie {{&message}} .

The default behavior is to escape all variables in Mustache. But you can do unescaped HTML like this {{{ message }}} .

See http://mustache.github.io/mustache.5.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM