Mastering Mustache Rendering Using Javascript

I am just starting to use Mustache and I have this rendering problem. I send data through the render function:

return Mustache.render(html, data);

or

return Mustache.to_html(html, data);

But when I add it to the div like:

$('#jqt').append(html);

It returns results similar to this in the actual text:

<div id="product_search_view">&lt;form class="search-form" &gt;&lt;ul class="rounded"&gt;&lt;li&gt;&lt;input type="text" id="label" name="search" placeholder="Enter what you are looking for"&gt;&lt;/li&gt;&lt;/ul&gt;&lt;a href="#" class="whiteButton submit" id="search-button" &gt;Search&lt;/a&gt;&lt;/form&gt;&lt;ul id="search-results" class="edgetoedge"&gt;&lt;/ul&gt;</div>

How can I make a mustache not put these characters?

+3
source share
2 answers

It looks like you passed the already-processed HTML to Mustache.

Here's a section of the documentation that discusses escaped characters and the use of triple whiskers.

In addition, here is another documentation . Read the Tag Types section and use &to prevent escaping.

+11

, -

var temp = Mustache.to_html(template, data_sources );

var correct_temp = $('<textarea />').html(temp).val();

$('#my_el').html(correct_temp);

, .

0

All Articles