Expand my Community achievements bar.

SOLVED

script validation error for or condition in sightly

Avatar

Level 2

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?
 
 
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Employee Advisor

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