简体   繁体   中英

How to compare two strings in Sightly/HTL? (AEM 6.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!

我相信HTL 条件三元运算符就是您要寻找的。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM