Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to declare, initialize and use a variable using SIGHTLY

Avatar

Level 7

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.

1 Accepted Solution

Avatar

Correct answer by
Employee

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

View solution in original post

10 Replies

Avatar

Correct answer by
Employee

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

Avatar

Level 3

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

Avatar

Level 7

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.

Avatar

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

Avatar

Employee

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

Avatar

Level 7

Hi Feike,

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

I got errors.

Thanks,

Arya.

Avatar

Employee

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

cheers,

Feike

Avatar

Employee

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

${message}

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

    <p>Content goes here</>

</div>

Avatar

Level 3

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-manage...

 

-A