Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

1st, 2nd, .... child of children


Reply

8 Posts   3012 Views

Avatar
Stephan.Schmidt

30 October 2007 at 9:46pm 3 Posts

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

Avatar
blacky

30 October 2007 at 9:59pm 3 Posts

I am new to sliver stripe
can u help me on this

how to place a dropdown control on middle of my page

Avatar
Sam

31 October 2007 at 10:22am (Last edited: 31 October 2007 10:22am), Administrator, 685 Posts

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 %>

Avatar
Stephan.Schmidt

1 November 2007 at 9:53am 3 Posts

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

Avatar
Sam

1 November 2007 at 4:54pm (Last edited: 1 November 2007 4:56pm), Administrator, 685 Posts

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! :-)

Avatar
Stephan.Schmidt

1 November 2007 at 6:34pm 3 Posts

Thanks Sam,

Cheers
-stephan

Avatar
Garrett

29 July 2008 at 9:45am Community Member, 245 Posts

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

Avatar
Garrett

1 August 2008 at 4:51am Community Member, 245 Posts

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