How to implement Switch statement Using sightly | Community
Skip to main content
rama_krishna11
New Participant
February 3, 2016
Solved

How to implement Switch statement Using sightly

  • February 3, 2016
  • 3 replies
  • 2680 views

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

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 Kunal_Gaba_

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>

3 replies

edubey
New Participant
February 3, 2016

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/ 

Kunal_Gaba_
Kunal_Gaba_Accepted solution
New Participant
February 3, 2016

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>
Jitendra_S_Toma
New Participant
February 3, 2016

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