I want to place a brace just before {{# .. }} expression Mustache expression. How can I do this? For example, for these inputs:
Hash:
{
"things": []
}
Output:
<pre>
{}
</pre>
Hash:
{
"things": [
{ "name": "thing1" },
{ "name": "thing2" },
]
}
Output:
<pre>
{
listOfThings: [
"thing1",
"thing2",
]
}
</pre>
The example is a bit synthetic in order to preserve simplicity.
My initial idea didn't work:
<pre>
\{{{#things}}
{{name}}
{{/things}}\}
</pre>
I would use HTML Entities for the desired literal curly braces in the output. Your example template would become the following:
<pre>
{{{#things}}
{{name}}
{{/things}}}
</pre>
However, I would like to point out that this template does not produce the desired output stated in your question. For that, you would need something like the following:
<pre>
{
listOfThings: [
{{#each things}}
"{{name}}",
{{/each}}
]
}
</pre>
I have created a fiddle for your reference.