Search code examples
arithmetic-expressionssightly

Does Sightly really not support any arithmetic operators?


I'm trying to subtract 2 from the total number of items in a list in Sightly.

<ul data-sly-list="${javaClass.list}">
    <li>
         <span> ${itemList.size -2 @ context='number'}</span>
    </li>
</ul>

The result is:

org.apache.sling.scripting.sightly.SightlyException: Parsing error in template ...: token recognition error at: '-' for expression ${itemList.size -2 @ context='number'}

Do I really have to create a method in Java for this? Like:

javaClass.getListCountMinusTwo()

I'd be grateful for any kind of workaround.


Solution

  • Sightly only supports logical and comparison operators (spec) and that is intended as the view rendering scripts are not supposed to contain business logic, this should come from the model/use-objects.