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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

Splitting ChildrenOf


Go to End


3 Posts   1068 Views

Avatar
Nev

Community Member, 5 Posts

29 January 2011 at 12:47am

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

Avatar
swaiba

Forum Moderator, 1899 Posts

29 January 2011 at 12:52am

Edited: 29/01/2011 12:54am

in your Page_controller do something like...

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

(note untested)

Avatar
Nev

Community Member, 5 Posts

30 January 2011 at 3:04am

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 !