In AEM, when we call some method or function to be used in our HTL front end code, something like this.
public boolean isAboolean() {
return "test";
}
and for the HTML, template language HTL
<sly data-sly-test.boolean="${property.Aboolean}" />
The same thing happens with "get", do we need to add it in the HTL code or can we just write the method name without "is" or "get"?
Do we have to do it this way, or will it work this way ?
<sly data-sly-test.boolean="${property.isAboolean}" />
The HTL specification is a bit generic and says that you can access members like this: ${myObject.key}
. The default implementation (Sling/AEM) follows the JavaBeans naming convention and will attempt to call either getKey()
or isKey()
. It will also attempt to call key()
or output a field named key
in case of POJOs. A bit more information is available in the AEM docs (Property Access section).
For your example, you need to adjust the case of the member in the HTL expression: ${property.aboolean}
and ${property.isAboolean}
should both result in calling isAboolean()
method.
Since it’s not allowed to call methods with parameters, parentheses are not used.