Hello,
how do I get the 1.,2.,... child of a children list? I do not wan't to iterate through them but just access the first 4 individually.
Thanks
-stephan
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Hello,
how do I get the 1.,2.,... child of a children list? I do not wan't to iterate through them but just access the first 4 individually.
Thanks
-stephan
I am new to sliver stripe
can u help me on this
how to place a dropdown control on middle of my page
Put this function in your Page class.
function LimitedChildren($limit) {
return DataObject::get("SiteTree", "ParentID = $this->ID", null, $limit);
}
then you can put this in your template:
<% control LimitedChildren(4) %>
...
<% end_control %>
Thanks for the reply, I more wanted to do
<% control child(1) %>
...
<% end_control %>
to access them individually for filling their content into slots
Thanks
-stephan
Well $limit is just the LIMIT clause of SQL; so, you could make it if you changed it to "$limit, 1", then that would return you the nth item.
If you wanted to use a single SQL query, you could have the function get all the items and save them to a local parameter the first time it was called, and after that just request from the object.
Long story short: There's nothing built-in for this, but it's only a few lines of PHP away...
Of course, I should probably mention why there's no feature to support that: in the 100s of sites we've built with SilverStripe, we've never needed that feature. Why? Because that kind of design inhibits your ability to add an extra item to the menu, with prevents your author from making the information architecture decisions that they should be allowed to make! :-)
Thanks Sam,
Cheers
-stephan
Hi,
Regarding your technique to Limit the number of Children returned-- how can I do this with Childern OF children?
I am in my NewsHolder template, which in turn contains other NewsHolders (Subject 1, Subject 2, Subject 3, etc.), and I want to simply get the LATEST 5, of that third level. I can get them all, of course, doing a nested <% control Children %> <% control Children %>, but what if I want to limit the number of records returned on the INside loop?? With a date sort?
Thanks in advance,
Garrett
Hi,
I need a technique to limit the number of Children returned from a certain object-- how can I do this with childern OF children?
I am in my NewsHolder template, which in turn contains other NewsHolders (Subject 1, Subject 2, Subject 3, etc.), and I want to simply get the LATEST 5, of that third level (the actuial news items INSIDE Subject 1, Subject 2, etc.). I can get them all, of course, doing a nested <% control Children %> <% control Children %>, but what if I want to limit the number of records returned on the INNER loop?? With a date sort?
How can this be achieved?
Thanks in advance,
Garrett