Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » 1st, 2nd, .... child of children

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

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

Page: 1
Go to End
Author Topic: 2944 Views
  • Stephan.Schmidt
    Avatar
    3 Posts

    1st, 2nd, .... child of children Link to this post

    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

  • blacky
    Avatar
    3 Posts

    Re: 1st, 2nd, .... child of children Link to this post

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

    how to place a dropdown control on middle of my page

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: 1st, 2nd, .... child of children Link to this post

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

  • Stephan.Schmidt
    Avatar
    3 Posts

    Re: 1st, 2nd, .... child of children Link to this post

    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

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: 1st, 2nd, .... child of children Link to this post

    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!

  • Stephan.Schmidt
    Avatar
    3 Posts

    Re: 1st, 2nd, .... child of children Link to this post

    Thanks Sam,

    Cheers
    -stephan

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: 1st, 2nd, .... child of children Link to this post

    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

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: 1st, 2nd, .... child of children Link to this post

    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

    2944 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.