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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Splitting ChildrenOf


Go to End


3 Posts   1346 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 !