Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Sightly comparison expression

Avatar

Level 3

Hi,

How can we compare the two values in Sightly test condition. i tried with below code but not working.

Ex:

 <sly data-sly-list="${}" >
 <sly data-sly-test="${itemList.index == ${properties.getvalue} }">Show some text</sly>  

</sly>

Here "getvalue" is property name with type textfiled in a dialog, we want to display some text when list count is matching with getvalue.

1 Accepted Solution

Avatar

Correct answer by
Employee

This is about the Sightly not casting to a different object-type.

To convert the index, you can do this trick.

data-sly-test.stringIndex="${'{0}' @ format=[itemList.index]}"

data-sly-test="${ stringIndex == properties.yourProperty}"

View solution in original post

10 Replies

Avatar

Level 3

1. I have removed the code  in {} before posting to forum.

2.. for comparison you can use ${itemList.index == properties.getvalue}"

 I am getting exception "

Invalid types in comparison. Equality is supported for String, Number & Boolean types

"

I thought we should convert the values to one type. I tried with @ context = 'number' but not able to get output.

Avatar

Level 10

What type of value does this return properties.getvalue, is it number or string ?

Avatar

Level 3

I am using xtype as "numberfield" for fixedlength property. i don't about return type for this xtype.

Avatar

Level 10

Take a look at docs, it says its " Numeric text field that provides automatic keystroke filtering and numeric validation."

https://docs.adobe.com/docs/en/cq/5-6/widgets-api/index.html?class=CQ.Ext.form.NumberField

Avatar

Level 10

Hi ,

properties.getvalue will return string which cannot be compared with itemList.index which is integer. Hence you are seeing the exception

Avatar

Correct answer by
Employee

This is about the Sightly not casting to a different object-type.

To convert the index, you can do this trick.

data-sly-test.stringIndex="${'{0}' @ format=[itemList.index]}"

data-sly-test="${ stringIndex == properties.yourProperty}"

Avatar

Level 10

also what property are you trying to compare with 

it should be something like property.<propertyname> which returns integer