Question

How make logical if and else with a parameter value in mustache ? like :

if ($a == "yes") 
  action
else
  action

or like,

if ($a == "yes") 
  action
else if ($a == "maybe") 
else
  action
Was it helpful?

Solution

Mustache can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object.

We call it "logic-less" because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values.

if suppose in general your statement is as follows:

enter code here if(notified_type == "Friendship")
    data.type_friendship = true;
    else if(notified_type == "Other" && action == "invite")
        data.type_other_invite = true;

then you can write it as

{{#type_friendship}}
    friendship...
{{/type_friendship}}
{{#type_other_invite}}
    invite...
{{/type_friendship}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top