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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

EventPage sorted by date - howto show only until today?


Go to End


3 Posts   2470 Views

Avatar
patte

Community Member, 63 Posts

22 February 2011 at 5:00am

Hi,

I have a problem with sorting by date...perhaps someone can help me out?

I have a EventHolder and a EventPage

in EventHolder.php i am sorting AllChildren() by a Date field

	function SortedChildren(){
	   $children = $this->AllChildren();	
	   if( !$children )
	      return null;
	   $children->sort('Date', 'ASC');	
	   return $children;
	}

in EventHolder.ss i list those EventPages

<% control SortedChildren %>
     <h2><a href="$Link">$Date.Format(d.m.Y) - $Title</a></h2>
     <p>$Content.FirstParagraph<a class="arrow" href="$Link">weiter</a></p>
<% end_control %> 

Now i want only to show EventPages with future dates. Old events should no longer be listed wen they are in the past.

Any idea?

Thanks much!

patte

Avatar
Bruce B

Community Member, 164 Posts

23 February 2011 at 5:07pm

Patte,
Try this:

function AllFutureChildren() {
$littlechildren = DataObject::get("EventPage", "Date >= CURDATE()", "Date ASC", null, null);
return $littlechildren;
}

add it to page.php so its accessible from all pages on the site.

Avatar
patte

Community Member, 63 Posts

14 March 2011 at 11:30pm

Thanks Bruce B ;-)

Works like a charm.