6

We are converting an old CMS using Mustachejs. The BODY of the content contains some html elements:

<strong>Mickey Mouse</strong> is a funny animal cartoon character created in 1928 by Walt Disney.

We we apply the value to Mustachejs like {{Description}}

The output rendered is

<strong>Mickey Mouse</strong> is a funny animal cartoon character
created in 1928 by Walt Disney.

Mustachejs literally displays the value as it is in the database.

How do we get Mustachejs to render the html markup as html?

Desired Result

Mickey Mouse is a funny animal cartoon character created in 1928 by Walt Disney.

Ravi Ram
  • 24,078
  • 21
  • 82
  • 113

1 Answers1

25

It's not literally displaying the value as it is in the db, it's encoding it. It's actually outputting

&lt;strong&gt;Mickey Mouse&lt;/strong&gt;

Use {{{three_braces}}} to have Mustache render without html encoding the string. {{{Description}}}

Popnoodles
  • 28,090
  • 2
  • 45
  • 53
  • Perfect ... so easy. Loving MustacheJS so far. – Ravi Ram Mar 07 '13 at 14:06
  • 2
    Note that when you use triple braces with user input, you should be careful to sanitize it before rendering. – bobthecow Mar 07 '13 at 14:33
  • And you should definitely do *whatever* @bobthecow says with regards to Mustache! – Popnoodles Mar 07 '13 at 18:03
  • Lucky that I came across this answer. Though my problem is not related to this question, but I was really struggling to display < and > as '<' and '>' respectively. Used three_braces and it worked like charm. Answer upvoted! – Ashish Vegaraju Feb 02 '17 at 13:58