Nested Ternary expression

tahir1601 15-06-2019

Hi all,

I am trying to implement something like below in sightly

<div class="${condition1?'class1:'condition2?'class2':'condition3?'class3':''''}">

I have 3 conditions, if condition1 is not met it goes to condition2 and then condition 3 and finally else case. I am getting error doing above.

Below is general logic

if(con1)

else if(con2)

else if(con3)

else

Please let me know how to implement in correct way in sightly.

Accepted Solutions (1)

Accepted Solutions (1)

Arun_Patidar
MVP
16-06-2019

Here is the example

<sly data-sly-test.if="${pageProperties.jcr:title == 'English1'}"></sly>

<sly data-sly-test.elseif1="${pageProperties.jcr:title == 'English2'}"></sly>

<sly data-sly-test.elseif2="${pageProperties.jcr:title == 'English'}"></sly>

<div class="${if?'class1':(elseif1?'class2':(elseif2?'class3':''))}">Demo</div>

In your case

<div class="${condition1?'class1':(condition2?'class2':(condition3?'class3':''))}">Demo</div>