Expand my Community achievements bar.

SOLVED

How to implement Switch statement Using sightly

Avatar

Level 2

For example, in jstl the switch statement like below

<c:choose><c:when test="${salary <= 0}"> Salary is very low to survive.</c:when><c:when test="${salary > 1000}"> Salary is very good.</c:when><c:otherwise>No comment sir...</c:otherwise></c:choose>

 

Need to convert the above switch statement to sightly. Please help me in this

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Try the following code- 

<div data-sly-test="${salary < 0}" data-sly-unwrap> Salary is very low to survive </div> <div data-sly-test="${salary >  1000}" data-sly-unwrap> Salary is very good. </div> <div data-sly-test="${salary < 1000} && ${salary > 0}" data-sly-unwrap> No comment sir... </div>

View solution in original post

3 Replies

Avatar

Level 9

All of these conditional changes, you should be doing in a simple POJO. It is better, If You should avoid such logic at the template level.

Jitendra

Rama Krishna wrote...

For example, in jstl the switch statement like below

 

Need to convert the above switch statement to sightly. Please help me in this

 

Avatar

Correct answer by
Employee Advisor

Try the following code- 

<div data-sly-test="${salary < 0}" data-sly-unwrap> Salary is very low to survive </div> <div data-sly-test="${salary >  1000}" data-sly-unwrap> Salary is very good. </div> <div data-sly-test="${salary < 1000} && ${salary > 0}" data-sly-unwrap> No comment sir... </div>

Avatar

Level 10

Hi Rama,

Approach I could suggest is, you can write this in sightly JS ( executes in server side) file as it supports switch. Take a look at this article on how you can us JS code sightly http://adobeaemclub.com/javascript-use-api-with-a-simple-component-in-sightly/