2

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
Vinod VT
  • 6,946
  • 11
  • 51
  • 75

1 Answers1

2

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}}
Ajit Kumar
  • 534
  • 3
  • 8
  • enter code here if(notified_type == "Friendship") data.type_friendship = true; else if(notified_type == "Other" && action == "invite") data.type_other_invite = true; <--- where i'm enter this code in php or mustache template file ? but thanks before – Muhamad Alfisyah Reza Daulay Oct 22 '13 at 09:53