1

I am working with a template in Craft 2, and I am setting up the criteria for entries to be displayed.
Here is my code (below).

{% set today = now|date('Y-m-d') %}

{% set criteria = {
    section: 'bulletin',
    order: 'postDate',
    expiryDate: '>=' . today
} %}

{% set initialEntry = craft.entries(criteria).first() %}
{% set finalEntry = craft.entries(criteria).last() %}

I get this error:

Impossible to access an attribute ("today") on a string variable (">="). 

How would I set expiryDate >= today?

2
  • 4
    In Twig, ~ is the concatenation operator! You can also use ">= #{today}", which Twig refers to as "string interpolation." This looks fine, otherwise. 👍 Jan 31, 2022 at 19:12
  • 1
    Ah! Thanks so much. I was still in PHP mode. :)
    – buck1112
    Jan 31, 2022 at 19:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.