Jump to:

3401 Posts in 979 Topics by 855 members

Template Questions

SilverStripe Forums » Template Questions » Splitting ChildrenOf

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

Page: 1
Go to End
Author Topic: 596 Views
  • Nev
    Avatar
    Community Member
    5 Posts

    Splitting ChildrenOf Link to this post

    Hi Everyone,

    Have a quick question I am looking to split the nodes of the ChildrenOf results. For example

    <div class="inner-box">
    <ul class="bor-none">
    <% control ChildrenOf(about-us) DISPLAY FIRST 4 %>
    <li><a href="$Link">$MenuTitle</a></li>
    <% end_control %>
    </ul>
    <ul>
    <% control ChildrenOf(about-us) DISPLAY SECOND 4 %>
    <li><a href="$Link">$MenuTitle</a></li>
    <% end_control %>
    <ul>
    <% control ChildrenOf(about-us) DISPLAY THIRD 4 %>
    <li><a href="$Link">$MenuTitle</a></li>
    <% end
    <span class="clear"></span> </div>
    </div>

    Any help would be greatly appreciated !

    Thanks

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Splitting ChildrenOf Link to this post

    in your Page_controller do something like...

    public function LimitedChildrenOf($parentRef,$iLimit) {
       $dos = $this->ChildrenOf($parentRef);
       return $dos->getRange(0,$iLimit);
    }

    (note untested)

  • Nev
    Avatar
    Community Member
    5 Posts

    Re: Splitting ChildrenOf Link to this post

    Thanks swaiba, used the following in the controller:

    public function LimitedChildrenOf($parentRef, $offset, $length) {
    $dos = $this->ChildrenOf($parentRef);
    return $dos->getRange($offset, $length);
    }

    and in the template:

    <% control LimitedChildrenOf(directory/mypage/, 0, 4 %>
    <li><a href="$Link">$MenuTitle</a></li>
    <% end_control %>

    <% control LimitedChildrenOf(directory/mypage/, 3, 4 %>
    <li><a href="$Link">$MenuTitle</a></li>
    <% end_control %>

    etc

    Simples !

    596 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.