adobe / htl-spec

HTML Template Language Specification
Apache License 2.0
280 stars 146 forks source link

Permit use of modulo operator within HTL conditionals #94

Open james-appleby opened 3 years ago

james-appleby commented 3 years ago

The restriction to only allow logical and comparative operators in HTL means modulus operations can't be performed.

<ul data-sly-test="${ model.items.size > 0 }" data-sly-list.item="${ model.items }">
    <sly data-sly-resource="${ item @ decorationTagName='li' }"></sly>
    <sly data-sly-test="${itemList.count % 5 ==0}"> ... </sly>    
</ul>

As well as using a constant ("5" in the example above) it should also be possible to use a HTL variable declared before the list or the result of a call into a Java model method, provided the value can be cast to an Integer.

While this does allow very limited business logic into the HTL layer, it's hard to see any other way of implementing a requirement within the list feature. This has been discussed in the past by other users here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/can-we-use-modulo-in-sightly/td-p/260156