I’m using mustache. I’m generating a list of notifications. A notification JSON object looks like:
[
{
"id": 1364,
"read": true,
"author_id": 30,
"author_name": "Mr A",
"author_photo": "image.jpg",
"story": "wants to connect",
"notified_type": "Friendship",
"action": "create"
}
]
With mustache, how can I do a if statement or case statement based on the notified_type & action…
If notified_type == "Friendship" render ……
If notified_type == "Other && action == "invite" render…..
How does that work?
Mustache templates are, by design, very simple; the homepage even says:
So the general approach is to do your logic in JavaScript and set a bunch of flags:
and then in your template:
If you want some more advanced functionality but want to maintain most of Mustache’s simplicity, you could look at Handlebars: