-
Notifications
You must be signed in to change notification settings - Fork 1
Existential Operator
Jair Andres Diaz Puentes edited this page Mar 15, 2018
·
2 revisions
You can use the existential operator #? to exclude an attribute altogether if the template evaluates to a falsy value.
var data = {
notifications: {
home: 1,
invite: 2
}
};
var template = {
tabs: [{
text: "home",
badge: "{{#? notifications.home}}"
}, {
text: "message",
badge: "{{#? notification.message}}"
}, {
text: "invite",
badge: "{{#? notification.invite}}"
}]
}
Select and transform
ST.select(template)
.transform(data)
.root();
Get the result
{
tabs: [{
text: "home",
badge: 1
}, {
text: "message"
}, {
text: "invite",
badge: 2
}]
}