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}}
Tim
May 2, 2019, 11:17am
2
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”.
Tim
May 2, 2019, 11:48am
4
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}}
Template scope inside js_if should be prefixed with: this.
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}}
Tim
May 2, 2019, 5:15pm
6
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