Closed wojciechgizynski closed 4 years ago
Really good question! For the library I maintain (https://gitlab.com/jobol/mustach) I added an extension for that behaviour: the single dot: when you put . for XXX it works as you expect. Subito I realize that this is not documented. See:
$ cat > ta.j
{
"key": { "door": "value123" }
}
$ cat > ta.t
{{#key}}
Value is {{.}}.
{{/key}}
{{^key}}
No key, no value!
{{/key}}
$ mustach ta.j ta.t
Value is { "door": "value123" }.
Thanks for the response. I'm preparing a Slack notification template from Kibana Alerts and it uses mustache. I don't have an option of using another library.
Nevermind, it's actually perfectly doable with simple:
{{#key}}
Value is {{key}}.
{{/key}}
Not sure how I've missed this.
Hi, I need some help preparing a template. I have the following hash:
I want to print
Value is: value123
only if there iskey
in the hash. How would I do that?What should I put in place of
XXX
to get the desired output? In other words, how do I display the value of a hash key that I based the section on, rather than a nested key value?I know that if the case would be
I could do
It's just not what I need right now.