This is the JSON array:
{
"profile": [
{
"ID": 343,
"gender": "female",
"from": "Olivia"
},
{
"ID": 4543,
"gender": "female",
"from": "Meagen"
},
{
"ID": 787,
"gender": "male",
"from": "Aaron"
}
]
}
This works and it outputs all the objects in the array…
{{#profile}}
{{from}} {{gender}}
{{/profile}}
Output will look like…
Olivia female
Meagen female
Aaron male
But my goal is to only loop those that have a gender equal to female. Something like…
{{#profile gender="female"}}
{{from}} {{gender}}
{{/profile}}
…and get the output to look like…
Olivia female
Meagen female
I’ve been struggling trying to find an answer for a few days. Am I missing something or am I way off track?
I see two options:
The first one is pretty straight forward.
The second depends on how you want to do it. You could add an “if equal” helper:
and do this in your template:
Demo: http://jsfiddle.net/ambiguous/NnH83/
Or you could write your own iterator in various ways:
Or a bit more general:
Demos: http://jsfiddle.net/ambiguous/E4jTs/, http://jsfiddle.net/ambiguous/AkZxN/
See the fine manual on Hash Arguments if you want something closer to your proposed syntax.