1

I am trying to work through deprecation warning. I have not touched Craft in a few months, so I am a bit rusty.

The Deprecation Message is:

DateTime::year is deprecated. Use the |date('Y') filter instead.

The offending line is:

{% for year in now.year .. firstEntryEver.postDate.year %}

Here is the context:

{% set firstEntryEver = craft.entries.section('posts').orderBy('postDate asc').one() %}
{% for year in now.year .. firstEntryEver.postDate.year %}                        
 <a href="/archives/{{ year }}" class="dropdown-item">
 <i class="material-icons">date_range</i> {{ year }}</a>
 {% endfor %}

So, how do I fix this?

1 Answer 1

1

This is how you fix this:

{# Old code #}
{% for year in now.year .. firstEntryEver.postDate.year %}

{# New code #}
{% for year in now.year .. firstEntryEver.postDate |date('Y') %}

Your Answer

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

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