Is there a list of all the options I can add to a loop?
I don't know if options is the right name for it. I mean these
<% loop Dataobject.Reverse %>
<% loop Dataobject.Limit() %>
Can someone tell me everything that's possible here? And what the correct name for it is?
there is an error in your question, it is <% loop $DataList.xxx %>
or <% loop $ArrayList.xxx %>
(see, you are looping a list of DataObjects)
well, loop
is basically just a foreach
loop
so, for example:
<% loop $DataList.Reverse %>$Title<% end_loop %>
is kindof the same as:
<?php
foreach($dataList->reverse() as $item) {
echo $item->Title;
}
'kindof' the same, because in fact the template does some checking and casting for you (eg it does not throw and error if Title is not set), and a loop can only loop SilverStripe lists, not arrays
tl;dr; / the conclusion
loop
has no options at all
the options that you speak of are methods that exist on the list that you want to loop.
the 2 lists php classes that you would normally loop are:
see the list of methods in the API docs for what methods are available.
obviously not all methods are meant to be used to loop,
only those that return a DataList
or ArrayList
will be useful.
you can see what they return from the first column of the table.
for example:
public ArrayList limit( integer $length, integer $offset = 0 )
means:
limit
so you can do: <% loop $List.limit(10,5) %>
further reading:
some methods in that list do not show parameters but actually do have them, this is because they are dynamic and the API docs fail to display that.
example:
public ArrayList filter( )
can be used like this (I think, never tried it):
<% loop $List.filter('Name', 'Zauberfisch') %>
you can also add your own methods by creating an Extension
and adding this Extension to DataList
and ArrayList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With