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   3056 Views

Avatar
Stephan.Schmidt

3 Posts

30 October 2007 at 9:46pm

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

3 Posts

30 October 2007 at 9:59pm

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

Administrator, 685 Posts

31 October 2007 at 10:22am

Edited: 31/10/2007 10:22am

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

3 Posts

1 November 2007 at 9:53am

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

Administrator, 685 Posts

1 November 2007 at 4:54pm

Edited: 01/11/2007 4:56pm

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

3 Posts

1 November 2007 at 6:34pm

Thanks Sam,

Cheers
-stephan

Avatar
Garrett

Community Member, 245 Posts

29 July 2008 at 9:45am

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

Community Member, 245 Posts

1 August 2008 at 4:51am

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