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.

Template Questions /

limiting childrenof


Reply


2 Posts   1178 Views

Avatar
netnerd85

Community Member, 42 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, 133 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