script validation error for or condition in sightly | Community
Skip to main content
arjunsudhas1995
Level 2
January 20, 2022
Solved

script validation error for or condition in sightly

  • January 20, 2022
  • 2 replies
  • 1145 views

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.
Best answer by JeevanRaj

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
January 20, 2022

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

milind_bachani
Adobe Employee
Adobe Employee
January 20, 2022

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