Reputation: 2206
I'm trying to make Mustache JS output content without parsing some variables. For example:
{{block.type}}-{{block.id}}-label-{{element.id}}
I want it to just parse the block, and that is why I am giving it the following JSON:
{ block: { type: 'news', id: 23 } }
The end result should be
news-23-label-{{element.id}}
but instead it is
news-23-label-
How should I make it not parse a part of the code? I'm new in Mustache JS and I could not find this in the documentation (comments I understood, if and foreach I understood, but I could not find this).
Upvotes: 0
Views: 129
Reputation: 241
Seems to be possible now. You can change and then restore the default delimiter. Example from documentation's Variables
section you can find here https://github.com/janl/mustache.js (see last three lines of template):
View:
{
"name": "Chris",
"company": "<b>GitHub</b>"
}
Template:
* {{name}}
* {{age}}
* {{company}}
* {{{company}}}
* {{&company}}
{{=<% %>=}}
* {{company}}
<%={{ }}=%>
Output:
* Chris
*
* <b>GitHub</b>
* <b>GitHub</b>
* <b>GitHub</b>
* {{company}}
Upvotes: 0
Reputation: 2555
Would this workaround help you? Click for fiddle.
HTML:
<div id="output"></div>
<script type="text/html" id="test1">
{{block.type}}-{{block.id}}-label-{{block.elId}}
</script>
JS:
var output = $("#output"),
template = $("#test1").html(),
data = '{ "block": { "type": "news", "id": 23, "elId": "{{element.id}}" } }',
html = Mustache.render(template, JSON.parse(data));
output.append(html);
Output:
news-23-label-{{element.id}}
Upvotes: 2