Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mustachejs render html markup as html

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.

like image 370
Ravi Ram Avatar asked Mar 07 '13 03:03

Ravi Ram


People also ask

How do I render a Mustache in HTML?

Including Mustache templates with partials You can also include a partial within another partial, which lets you make nested includes. Then, when you run the Mustache processor, you pass your partials object as the third argument, like this: html = Mustache. render( template, data, partials );

What is Moustache HTML?

DESCRIPTION. Mustache can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object. We call it "logic-less" because there are no if statements, else clauses, or for loops. Instead there are only tags.

How do I create a Mustache template?

The Mustache templates consist of tag names surrounded by { { } } (which resemble mustaches – hence the name) and are backed by a model object containing the data for the template.

What is Mustache script?

Mustache is a web template system with implementations available for ActionScript, C++, Clojure, CoffeeScript, ColdFusion, Common Lisp, Crystal, D, Dart, Delphi, Elixir, Erlang, Fantom, Go, Haskell, Io, Java, JavaScript, Julia, Lua, .


1 Answers

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}}}

like image 186
Popnoodles Avatar answered Oct 20 '22 21:10

Popnoodles