Grouping items in a repeater using a macro expression
The following article shows how to group a certain count of items in a repeater using a macro expression in a TEXT/XML transformation. This way you will be able to group e.g. every three items in a specific div.
First open the transformation of your repeater, and switch it to TEXT/XML transformation as you can see in the following screenshot.
In order to achieve the desired output, you need to get the index of the current item. You may get it by using:
{% DataItemIndex %}. This combined with a proper
modulo function will enable you to group items.
This example shows how to group every tree items:
{% if (DataItemIndex mod 3 == 0) {"<div style=\"background-color:#FFA9A9\">"}#%}
<h2>{% NewsTitle %}</h2>
{% if (DataItemIndex mod 3 == 2 || DataItemCount-1 == DataItemIndex) {"</div>"}#%}
The output of this will be:
-rs-
Applies to: Kentico CMS 7.x