1

The following code is throwing an error for me.

{% set eventEntries = craft.entries.find({
    section: 'events',
    event_startDateTime: '<= {{ now }}',
    limit: '4'
}) %}

{% for entry in eventEntries %}

Fatal error: Call to a member function getTimestamp() on a non-object

What I'm trying to do is pull 4 events where a date field (event_startDateTime) is before the current time. My suspicion is that the {{ now }} variable isn't parsing inside the single quotes, but I'm not entirely sure. Can anyone correct my code?

2

In Twig, you'll never need to double up on your curly brackets. I.E.

{{ {{ }} }}

or

{% {{ }} %}

Change this (which is already inside of {% %}:

event_startDateTime: '<= {{ now }}',

To use string concatenation like this:

event_startDateTime: '<= ' ~ now,

And you should be set.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.