Skip to main content
arjunsudhas1995
Level 2
Jan 20, 2022 7:46 AM UTC
Solved

script validation error for or condition in sightly

I have tried the following snippets for testing whether an 'OR' condition gets satisfied in sightly.

<sly data-sly-test=" ${roottitle!='en'||roottitle!='es'}">
 <sly data-sly-test=" ${roottitle!='en'||'es'}">
 
if this is success then there are a series of markup to be added
Both statements result in build error saying:
redundant constant value comparison
How to do proper or condition and check multiple values properly in sightly?
 
 
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
JeevanRaj
JeevanRajAccepted solution
Community Advisor
Jan 20, 2022 8:29 AM UTC

Hi @arjunsudhas1995 

 

Below is one of the way to check OR condition in HTL.

 

<sly data-sly-test.roottitle="fr"/>
<p data-sly-test="${roottitle != 'en'|| roottitle != 'es'}">${roottitle}</p>

 In the first line i'm setting the value fr to the variable roottitle. In the second line i'm printing roottitle only if it not equal to en or es. Let me know if you have any further questions.

 

Thanks

2 replies

JeevanRaj
Community Advisor
JeevanRajCommunity AdvisorAccepted solution
Community Advisor
Jan 20, 2022 8:29 AM UTC

Hi @arjunsudhas1995 

 

Below is one of the way to check OR condition in HTL.

 

<sly data-sly-test.roottitle="fr"/>
<p data-sly-test="${roottitle != 'en'|| roottitle != 'es'}">${roottitle}</p>

 In the first line i'm setting the value fr to the variable roottitle. In the second line i'm printing roottitle only if it not equal to en or es. Let me know if you have any further questions.

 

Thanks

Translate
milind_bachani
Adobe Employee
Adobe Employee
Jan 20, 2022 9:03 AM UTC

Hi @arjunsudhas1995 

If you are fetching the roottitle from properties you can simply use :

<div class="mytest">
    <sly data-sly-test="${properties.roottile != 'root' || properties.roottile != 'roottitle1'}">
    	Inside rootTitleCond
    </sly>

    <sly data-sly-test="${properties.roottile != 'root' || 'roottitle1'}">
    	Inside rootTitleCondnEW
    </sly>
</div>

Both the conditions work for me. Make sure you use proper whitespacing before and after operators like I have used. Otherwise, sightly will fail to work


Thanks

Translate