Need clarification on data-sly-test usage in sightly file | Community
Skip to main content
Level 9
February 1, 2016
Solved

Need clarification on data-sly-test usage in sightly file

  • February 1, 2016
  • 8 replies
  • 1797 views

Hi All,

In sightly file, I have a set of conditions as below, based on which certain processing happens :

1]<div class="item " data-sly-test="${condition2 || condition1 || condition3}">
2]<div class="item " data-sly-test="${condition2 || condition3}">
3]<div class="item " data-sly-test="${condition1}">

Condition #1 is occuring 3 times, Condition #2 : 2 times and Condition #3 : 1 time.

a] Can someone please let me know what exactly does these conditions imply. Explanation on this will be helpful.

b] If I have to re-create the same thing in Java, how would I do that.

Any thoughts/pointers on this will be helpful.

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 leeasling

I don't know that I really understand what you'e asking for, but here's an attempt to answer for you:

These would be the same as writing the following in Java.  They're simply OR statements - if any of your conditions are true/not null/not empty, then the element will be rendered.

if (condition1 || condition2 || condition3) { //Do Something } if (condition2 || condition3) { //Do Something } if (condition1) { //Do Something }

If that doesn't answer for you, could you maybe try to ask the question a little more specifically?

8 replies

leeaslingAccepted solution
Level 8
February 1, 2016

I don't know that I really understand what you'e asking for, but here's an attempt to answer for you:

These would be the same as writing the following in Java.  They're simply OR statements - if any of your conditions are true/not null/not empty, then the element will be rendered.

if (condition1 || condition2 || condition3) { //Do Something } if (condition2 || condition3) { //Do Something } if (condition1) { //Do Something }

If that doesn't answer for you, could you maybe try to ask the question a little more specifically?

askdctmAuthor
Level 9
February 1, 2016

Hi Leeasling,

Thank you for your reply.

In case, condition1 is true in the first and third if statement, then processing statements mentioned in both the if conditions will be run?

smacdonald2008
Level 10
February 1, 2016

They are separate condition expressions - as Lee pointed out. So:

if (condition1 || condition2 || condition3) {
    //Do Something
}
if (condition2 || condition3) {
    //Do Something
}
if (condition1) {
    //Do Something
}

Each condition is a OR - not an AND. Therefore if condition 2 is true - then the 1 and 2 expression is executed. 

Level 8
February 1, 2016

Right, with the way you currently have it configured, #1 and #3 would be output if condition1 is true.

kautuk_sahni
Community Manager
Community Manager
February 2, 2016

Hi 

As mentioned by Lee and Scott, they are 3 conditional statements. 

if (condition1 || condition2 || condition3) {
    //Do Something 1
}
if (condition2 || condition3) {
    //Do Something 2
}
if (condition1) {
    //Do Something 3
}

 

Case 1 :-  Let condition1 = true,  condition2 = False and condition3 - false.

So here "Do Something 1" and "Do Something 3" will be rendered.

 

Case 2 :- Let condition1 = false,  condition2 = true and condition3 - false.

So here "Do Something 1" and"Do Something 2" will be rendered.

 

Note :- || is or operator, so any of the statement is if true then it will be true. i.e. 1 OR 0 OR 0 Or 0 Or 0..... = 1

 

Reference Link :- http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-1/ (Sightly introduction)

I hope this will clear your doubt.

Thanks and Regards

Kautuk Sahni 

Kautuk Sahni
askdctmAuthor
Level 9
February 2, 2016

Hi Kautuk,

Thank you for your reply.

One Doubt.

In "Case:2" that you have mentioned[i.e, condition1 = false,  condition2 = true and condition3 - false],.

a] Will not "Do Something 2" and "Do Something 1"  be executed?[because condition2 is satisfied in the first and second "if" condition] 

kautuk_sahni
Community Manager
Community Manager
February 2, 2016

askdctm wrote...

Hi Kautuk,

Thank you for your reply.

One Doubt.

In "Case:2" that you have mentioned[i.e, condition1 = false,  condition2 = true and condition3 - false],.

a] Will not "Do Something 2" and "Do Something 1"  be executed?[because condition2 is satisfied in the first and second "if" condition] 

 

Hi, 

you are correct, i missed it.

I have edited that answer. Please check and verify it.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
askdctmAuthor
Level 9
February 3, 2016

Hi Leeasling/Scott/Kautuk,

Thank you for your answers. It helped.