How to compare two strings in Sightly/HTL? (AEM 6.2)

2.8k Views Asked by At

I have created a simple dropdown with two options Yes and No which return the values of "true" and "false" respectively.

<enableTool
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/select"
class="cq-dialog-dropdown-showhide"
cq-dialog-dropdown-showhide-target=".list-option-listfrom-showhide-target"
fieldLabel="Enable tooltip?"
name="./enableTool">
    <items jcr:primaryType="nt:unstructured">
        <true
            jcr:primaryType="nt:unstructured"
            text="Yes"
            value="true"/>
        <false
            jcr:primaryType="nt:unstructured"
            text="No"
            value="false"/>
    </items>
</enableTool>

I want to implement the following logic in sightly

if (value of the returned string is true)
{
Do something
}

For This is wrote the following sightly code

<div data-sly-test="${properties.enableTool == 'true'}"> Value is true</div>

when I run this "Value is true" is always printed irrespective of the fact whether the the value of propeties.enableTool is true or false.

please note that if I write <div> ${properties.enableTool} </div> , I see the values as true or false ,correctly, as per my selection.

Any idea what am I doing wrong?

Thanks in advance!

1

There are 1 best solutions below

0
On

I believe the HTL Conditional Ternary operator is what you're looking for.

<p>${properties.enableTool ? "tool is enabled" : "tool is disabled"}</p>