Sightly comparison expression | Community
Skip to main content
Balu_M
Level 3
October 16, 2015
Solved

Sightly comparison expression

  • October 16, 2015
  • 10 replies
  • 9901 views

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.

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

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}"

10 replies

Balu_M
Balu_MAuthor
Level 3
October 16, 2015

Thanks for your help. 

Lokesh_Shivalingaiah
Level 10
October 16, 2015

also what property are you trying to compare with 

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

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

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}"

Lokesh_Shivalingaiah
Level 10
October 16, 2015

Hi ,

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

edubey
Level 10
October 16, 2015

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

Balu_M
Balu_MAuthor
Level 3
October 16, 2015

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

edubey
Level 10
October 16, 2015

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

smacdonald2008
Level 10
October 16, 2015
Balu_M
Balu_MAuthor
Level 3
October 16, 2015

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.

edubey
Level 10
October 16, 2015

Two things seems to be wrong:

1. data-sly-list="${}"  is empty, which should not be

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

Please see these article to get these things clear..