Expand my Community achievements bar.

AEM6.3 equals compare on sightly template

Avatar

Level 3

Hi,

I am reading a java object on an sightly template and I have a js server-side.

I am trying to compare a value from this js server-side with a value of my java list.

When I print the compare on my page it evaluates as true, but when I put this same code inside a data-sly-test, the value seems not true as the code inside is not executed, but I am printing out this condition and is true. My code:

<sly data-sly-use.data="${'xxx.xxxx.xxxx.xxxxxx.core.access.resource.ContingencyAccess' @ market=util.market}" data-sly-list.item="${data.contingencyList}" data-sly-test.="${util.month_back[0].month == item.month}">

Is not posible to do this kind of compare inside sightly code?

How should I deal with it?

Thank you very much in advance!

6 Replies

Avatar

Level 10

Why not do compare operations using Java using Sling midel or WCMUsePojo?

Avatar

Level 10

think of HTL as the View and Java as setting the data to be displayed. You can control the data much better in Java and place the data in collections that the HTL can Display.

Avatar

Level 3

Hi Scott,

Thank you for your reply,

we are doing our logic on java, but it has some validations that I have to do on layout, like if  the item on my list is this one I show on this way and if returns that I show on that way.

I am trying to think some workaround to do this, but I was wondering if is this not really posible to do on sightly.

Thank you once more

Avatar

Level 10

Well HTL does support comparison operators as discussed here:

htl-spec/SPECIFICATION.md at 1.3 · Adobe-Marketing-Cloud/htl-spec · GitHub

I have always done in Java and then set the Beans or collections that are displayed!

Avatar

Community Advisor

HI Elizabeth,

From the snippet pasted in your original post, could observe a "." after data-sly-test. Not sure if it is a typo here or in the code taken from your HTL. If it is not typo in your actual HTL, then try doing the below

Capture the comparison value and then proceed further:

    

    data-sly-test.cmpVal = "${}"

     data-sly-test=${!cmpVal} or ${cmpVal}

Avatar

Level 3

Hi,

The problem was that we was doing everything inside the same tag <sly>

and it was getting confused when processing

We divided the compare on two tags <div> and now are working.

Thank you