17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 3275 Views |
-
if Pos < 5 - this doesn't work

10 July 2008 at 4:45pm
Is there any way to do this? I want just the first 4 children of a section, so I figured I could write
<% if Pos < 5 %>
but it fails, blank screen. It seems like the problem is the "less than" operator since "equals" works fine. Does SS not support "less than" or "greater than"?
-
Re: if Pos < 5 - this doesn't work

10 July 2008 at 8:01pm Last edited: 10 July 2008 8:13pm
No, it doesn't support what you're doing.
The best way to solve what you're doing is to create a custom function for your <% control block, and filter the results using the limit argument to DataObject::get()
e.g.
class Page extends SiteTree {
...
function ChildrenWithLimit($limit = 4) {
return DataObject::get('Page', "ParentID = $this->ID", '', '', $limit);
}...
}
Then, you can use <% control ChildrenWithLimit %> in your template. Should you want to override the default of 4, you can use <% control ChildrenWithLimit(8) %>, for example.
-
Re: if Pos < 5 - this doesn't work

10 July 2008 at 9:05pm
thanks, that sounds great, except the children I'm trying to pull in aren't children of the page I'm on. I was using ChildrenOf(page-url). How would I use that in the get function?
-
Re: if Pos < 5 - this doesn't work

10 July 2008 at 10:14pm
Considering you are hard coding the url in the theme then you could hard code this in the code and use the ParentID column in the database and compare it against the ID of the pages url
function ChildrenWithLimit($limit = 4) {
$Parent = DataObject::get_one("Page", "URLSegment = 'page-url'");
return ($Parent) ? $Children = DataObject::get("Page", "ParentID = '$Parent->ID'","","", $limit) : false;
} -
Re: if Pos < 5 - this doesn't work

27 August 2011 at 2:52pm
Hi,
I finding the way to display record from dataobject by escape first top three records. Does any one have any idea?
I am really appreciated your reply.Thanks
Bunheng
| 3275 Views | ||
|
Page:
1
|
Go to Top |



