Jump to:

23471 Posts in 18937 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » $Now not available in dataobject

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: 261 Views
  • Bronwyn
    Avatar
    Community Member
    16 Posts

    $Now not available in dataobject Link to this post

    Hi, I'm trying to use something like
    <% if InFuture(EndDate) %> or <% if EndDate.InFuture %>
    inside a control to get the next few events to put on a home page.

    The control is calling upcoming events, which are defined by this function:

    function UpcomingEvents($num=3) {
    return DataObject::get("EventObject", "", "StartDate DESC", "", $num);
    }

    Nothing works.

    If I put $Now outside my <% control %> block I get today's date, but anywhere inside it I get nothing. I have come to the conclusion that today's date is just not available to use within my control, which means that I can't use it to tell whether or not things are in the future.

    My control is running through objects, not pages.

    What I think I might have to do is incorporate it into the function up there^ but my function writing skills are minimal and I don't know how. I need to put in a filter I think.

    Any help would be much appreciated.

    Edit: I think I've found it. This post was very helpful - don't know why I couldn't find it before http://www.silverstripe.org/data-model-questions/show/12646

    261 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.