2

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!

Archit Arora
  • 2,508
  • 7
  • 43
  • 69
  • 3
    I don't see an issue with your code. It should work fine. To better debug, please add more code related to dialog and the HTL file. – rakhi4110 Jul 24 '17 at 05:40
  • 1
    I have created a field with the provided code and used the same sightly code to check the test condition and it is working fine for me, Sightly code I have used :
    Value is true
    Value is false
    – Ekta Aggarwal Jul 24 '17 at 07:44
  • 1
    Like the two comments above, I dont see issues in your code, what version of AEM are you using? also, i suggest you use the HTL REPL for quick HTL testing: https://github.com/Adobe-Marketing-Cloud/aem-htl-repl – Ahmed Musallam Jul 24 '17 at 18:08

1 Answers1

0

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

<p>${properties.enableTool ? "tool is enabled" : "tool is disabled"}</p>
Blatmann
  • 11
  • 1
  • 2