How to declare, initialize and use a variable using SIGHTLY | Community
Skip to main content
Dinu_Arya
Level 6
October 16, 2015
Solved

How to declare, initialize and use a variable using SIGHTLY

  • October 16, 2015
  • 10 replies
  • 8232 views

Hi,

I have a requirement which needs a counter integer variable to be incremented in loop or a flag variable to be set to 0/1 or true/false. I've to show 1st item using some UI and the rest of the items with another UI. How can I achieve using sightly? I have referred tutorials but no where mentioned how to create a variable in sightly as <c:set var="variableName" value="variableValue"/> in JSTL. Please help me in this.

Thanks,

Arya.

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 Feike_Visser1

You can do that like this...

<div data-sly-test.yourName="${currentPage.name}" data-sly-unwrap></div>

Now you do things like

<div data-sly-test="${yourName}">....${yourName}</div>

best,
Feike

10 replies

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

You can do that like this...

<div data-sly-test.yourName="${currentPage.name}" data-sly-unwrap></div>

Now you do things like

<div data-sly-test="${yourName}">....${yourName}</div>

best,
Feike

Level 3
October 16, 2015

Hi Feike,

Not sure if this is how it is supposed to work. If it is, how do I get my code working?

I have a requirement as below:

<div d-automode="${obj.message}"> <p>Content goes here</> </div>

The value of ${obj.message} is either 'true' or 'false'. But, when the value is false, sightly completely removes the attribute 'd-automode' and the resulting HTML is as below:

<div> <p>Content goes here</> </div>

How do I set value of 'false' in this attribute?

Cheers,

ashtrick

Dinu_Arya
Dinu_AryaAuthor
Level 6
October 16, 2015

Feike Visser wrote...

You can do that like this...

<div data-sly-test.yourName="${currentPage.name}" data-sly-unwrap></div>

Now you do things like

<div data-sly-test="${yourName}">....${yourName}</div>

best,
Feike

 

 


Hi Feike,

Thanks. It worked for me. For setting purpose this is ok. But we can't increment a variable in sightly. Also we can't check whether an object is null or not. I tried to check whether the object is null or not. But I got errors. Adobe has to provide these features. I think some background work is going on to implement these features. We can follow this for time being. I hope soon they will answer all these questions/issues related to Sightly.

Thanks,

Dinakar.

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015
  1. try this:
  2.  
  3. <div d-automode="${obj.message ? 'true' : 'false'}">
  4. <p>Content goes here</>
  5. </div>
Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

hi,

Give me your example, where you get these errors.

Indeed you can't increment a counter, you should use a use-class for that.

Checking for null can be done like data-sly-test="${objectToBeChecked}

best,

Feike

Dinu_Arya
Dinu_AryaAuthor
Level 6
October 16, 2015

Hi Feike,

I tested like this ->  data-sly-test="${objectToBeChecked != null}"

I got errors.

Thanks,

Arya.

Level 3
October 16, 2015

Already tried, no luck sad

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

just use this data-sly-test="${objectToBeChecked}" or data-sly-test="${!objectToBeChecked}".

cheers,

Feike

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

<div data-sly-test.message="${'false'}"></div>

${message}

<div d-automode="${message ? 'true' : ' false '}">

    <p>Content goes here</>

</div>

Level 3
October 16, 2015

Thanks Feike.

I have created a separate thread for this problem. Will continue this discussion there. Below is the link

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__ss1j-im_having_thisprobl.html

 

-A