SilverStripe Children Of, cycle only 3 times

I try to run the loop only 3 times, no matter how much it had.

<% loop $ChildrenOf(Sponsors) %>
        <li>
            <a href="$TargetURL" target="_blank">
                <img src="$Logo.Link" alt="image" />
            </a>
        </li>
    <% end_loop %>

What I thought about what I am doing is declaring a counter variable, and if it falls into 3 call breaks, however, when I do this:

<% $counter = 0 %>

page breaks, this does not cause any errors, but any line of code after that does not work.

How can I make this cycle break after it starts 3 times?

+3
source share
1 answer

This is described in the SilverStripe Templates documentation . This should work:

<% loop $ChildrenOf(Sponsors).Limit(3) %>
    <li>
        <a href="$TargetURL" target="_blank">
            <img src="$Logo.Link" alt="image" />
        </a>
    </li>
<% end_loop %>
+7
source

All Articles