Jump to:

23355 Posts in 17838 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » EventPage sorted by date - howto show only until today?

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

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

Page: 1
Go to End
Author Topic: 1419 Views
  • patte
    Avatar
    Community Member
    63 Posts

    EventPage sorted by date - howto show only until today? Link to this post

    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

  • Bruce B
    Avatar
    Community Member
    145 Posts

    Re: EventPage sorted by date - howto show only until today? Link to this post

    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.

  • patte
    Avatar
    Community Member
    63 Posts

    Re: EventPage sorted by date - howto show only until today? Link to this post

    Thanks Bruce B ;-)

    Works like a charm.

    1419 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.