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

Displaying only the first 3 Children


Go to End


5 Posts   3765 Views

Avatar
Noel

Community Member, 8 Posts

1 June 2010 at 10:14am

I want the ArticleHolder.ss (as per the tutorial) to only display the first 3 Children.
Any ideas anyone?

Avatar
3dgoo

Community Member, 135 Posts

4 June 2010 at 2:43pm

Avatar
Noel

Community Member, 8 Posts

8 June 2010 at 5:05pm

thanks for that - I'm a bit of a novice on all this ....
so I've figured out that the function needs to be declared in the php controller
- but I'm a but confused about how to 'call' this function inside (?) the .ss <% control Children %> loop

Avatar
3dgoo

Community Member, 135 Posts

8 June 2010 at 5:18pm

You're doing well by asking questions.

So you have a function in your controller something like this:

public function GetChildren($Limit = 5){
    return DataObject::get("PageType", "ParentID = $this->ID", Null, Null, $Limit);
}

In your template you would have:

<% control GetChildren(3) %>
    <h2>$Title</h2>
    $Content.LimitWordCount
<% end_control %> 

You call the control on GetChildren instead of Children.

Make sense?

Avatar
Noel

Community Member, 8 Posts

8 June 2010 at 5:31pm

cool - thanks mate - much appreciated !!!