Sightly incrementing numbers
Hi All,
Is there a way to increment an integer within a sightly block? I like to convert the JSP code to Sightly, but it looks like Sightly lacks the capability of incrementing. Here's what I like to achieve:
JSP:
<c:set var="counter" value="1"/>
<c:set var="blockOpen" value="false"/>
<c:forEach items="${comp.items}">
<c:set var="counter" value="${counter+1}"/>
// -- if blockOpen, will print out <li>, later will close the <li> tag depending on the condition
// the <li> tag will carry the counter as
<li class="my-list__${counter}">
// -- under some conditions
<c:set var="blockOpen" value="${true}"/>
</c:forEach>
My best understanding is that the most similar code in Sightly will a list, but it's quite different from JSP. First of all you can't increment the counter, second, you can't toggle the boolean values. For instance,
<sly data-sly-set.blockOpen="false"/>
<sly data-sly-repeat="whatever">
// -- trying to create utility sling model by injecting the number, and it fails
<sly data-sly-use.myUtils="${'mysite.models.UtilsModel' @ counter = my_number_here}">
...
// incrementCounter takes care of the logic, no luck
<sly data-sly-set.counter="${myUtils.incrementCounter}"/>
// -- won't pick this up, either, if I print out ${blockOpen}, it's always false
<data-sly-set.blockOpen="true"/>
</sly>
Is it the only way to achieve this is to create a sling model helper completely taking care of the html code?
Thank you very much!
-kt

