I'm moving e-mail templates from Mandrill to Postmark which requires converting Handlebars to Mustachio. In Handlebars I had something like this:
{{#if some_variable}}
<p>This text uses variable: {{some_variable}}
{{/if}}
According to Mustache documentation it should look like this after converting:
{{#some_variable}}
<p>This text uses variable: {{some_variable}}
{{/some_variable}}
The problem is that Postmark's Mustachio uses scoping (https://github.com/wildbit/mustachio/wiki#scoping), so in that case it expects following JSON model:
{
"some_variable": {
"some_variable": "some_variable_value"
}
}
instead of
{
"some_variable": "some_variable_value"
}
Does anyone know how to turn off Mustachio's scoping, so it uses expected exemplary JSON model? The only workaround (dirty one) I see so far is to pass template model in this nested object form, but I already found out that it wont work in all cases. Thanks in advance, any help appreciated.
Ok, found an anwser to that problem. According to the docs https://github.com/wildbit/mustachio/wiki#inverted-groups-or-how-to-make-placeholders what I should do in that case is:
{{#some_variable}}
<p>This text uses variable: {{.}}</p>
{{/some_variable}}
Then sending JSON model like:
{
"some_variable": "some_variable_value"
}
will result in
<p>This text uses variable: some_variable_value</p>
So the answer to the problem is to use {{.}} operator that points to the tag value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With