I now need to split the loop every 3 items, so it looks something like the following when it is output:
<wrapper>
<image>
<image>
<image>
</wrapper>
<wrapper>
<image>
<image>
<image>
</wrapper>
<wrapper>
<image>
<image>
</wrapper> <!-- last row can have less than three if needed -->
What is the best way of achieving this with Kirby?
This if statement is pretty useless, because it will always be true (because toFiles() always returns a files collection object, which might or might not be empty). I have replaced this condition with a check for an empty collection.
This is different fromtoFile()/toPage() which returns either a file/page object or null.