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

limiting childrenof


Go to End


2 Posts   1722 Views

Avatar
jaybee

Community Member, 49 Posts

21 May 2010 at 8:42am

I'm trying to use ChildrenOf but limit the amount of results, I tried the following and it did not work for me:

<% control ChildrenOf(blog) %>
   <% control Range(0,3) %>
      $Content
   <% end_control %>
<% end_control %>

The code above is from here: http://www.silverstripe.org/archive/show/160555#post160555

Anyone know of a way?

Avatar
3dgoo

Community Member, 135 Posts

25 May 2010 at 1:16pm

I can't find any information about the control Range, and I can't get it to work. So I assume this was a feature of 2.2 that was dropped in 2.3.

What you could do is create a function to do this in your Controller:

function BlogEntries()
{
	return DataObject::get("BlogEntry", NULL, NULL, NULL, "0, 3");
}

In your template:

<% control BlogEntries %>
$Content
<% end_control %>

Check out DataObject::get to see the parameters for sorting and where clauses if you need them:
http://doc.silverstripe.org/datamodel#querying_data