Multiple condition in template

I have a complex operator trying to archive this below multiple condition in template.

  if ( $permission == $authorization || $permission =="Top_Secret" || $permission =="Confidential" || $permission =="Secret" || $permission =="Restricted") {

     } elseif ($permission !="Top_Secret" && $permission =="Confidential" || $permission =="Secret" || $permission =="Restricted") {
     	# code...
     } elseif ($permission !="Top_Secret" || $permission !="Confidential" && $permission =="Secret" || $permission =="Restricted") {
     	# code...
     } elseif ($permission !="Top_Secret" || $permission =="Confidential" || $permission =="Secret" && $permission =="Restricted") {
     	# code...
     } else {
     	# code...
     }

any guide about how to make Multiple condition in

Template7.registerHelper

I review this topic Evaluating conditions within Template7

it help me in many cases but I did not find any Multi condition like above. please give me an example how to make this work.

I have try this but not work:

{{#each category.catdata}}
 {{#if @root.category.permission "==" authorization "||" @root.category.permission "==" "Top_Secret" "||" @root.category.permissionon "==" "Confidential" "||" @root.category.permission "==" "Secret" "||" @root.category.permission "==" "Restricted"}}
<My DIV CONTENT />
{{/if}}
{{/each}}

Instead of the #if operator (which only checks simple conditions), you could use the #js_if operator for extented conditions like this:

<p>
  {{#js_if "validPage && (!loginRequired || loggedIn)"}}
    Your content
  {{else}}
    Content unavailable
  {{/js_if}}
</p>

Thank for your reply but how can I achieve this
{{#js_if @root.category.permission "==" authorization "||" @root.category.permission "==" "Top_Secret" }}
using “js_if”.

Not sure about @root, but the overall syntax should be something like this:

{{#js_if "[email protected] == 'authorization' || [email protected] == 'top_secret'"}}
  Content to show
{{/js_if}}
  1. Template scope inside js_if should be prefixed with: this.
  2. You can’t use double quotes, or should escape them properly. But most of the time, single quotes are easier.
1 Like

Thank you your guidance, working perfectly.

This is the final code:

{{#js_if "@root.category.permission == this.authorization || [email protected] == 'Top_Secret' || @root.category.permissionon == 'Confidential' || @root.category.permissionon == 'Secret' || @root.category.permissionon == 'Restricted'"}}

can I use else if for more nested conditions ? answer is Yes, its working like this.

{{#js_if  conditions}}
#something
{{#else_if  conditions}}
#something
{{/js_if}}

Nice! Besides, are you sure #else_if works? That would be great, as I thought it still was a future request on Github. @nolimits4web ?

1 Like

Yes, I already apply on my current project using above nested conditions.

1 Like

i use that to work with multiples conditions, hope help you

<div class="col-25">
{{#js_if "this.tipo === 'catalogo'"}}
    <span class="Montserrat-Bold">Duzani</span>
{{else}}
    {{#js_if "this.tipo === 'catalogoClothingDuzani'"}}
        <span class="Montserrat-Bold">Clothing</span>
    {{else}}
        <span class="Montserrat-Bold">Lageli</span>
    {{/js_if}}
{{/js_if}}
</div>
1 Like