1

I have two channels: A event and a news channel which I want the cache to expire based on both their expiry Date.

{% set newsDate = craft.entries.section('newsDate').order('expiryDate asc').first() %}
{% set eventDate = craft.entries.section('event').order('konzertStartdate asc').first() %}
{% set currentTime = now |date('c') %}

{% if currentTime <= newsDate %}
    {% set invalidate = newsDate.expiryDate | date('c') %}
{% else %}
    {% set invalidate = auffuehrung.konzertStartdate |date('c') %}
{% endif %}

{% cache unless invalidate %}
 {# blablabla #}
{% endcache %}

As you can see I create two variables and then check which one is newer. But its not working properly.

The news never seem to invalidate the cache.

Do you know a better way to do this?

2
  • 1
    Is it possible that you wanted to write "until" instead of "unless" in the template code? – Andris Sevcenko Nov 30 '16 at 12:06
  • If you output {{ newsDate }}, {{ eventDate }} and {{ currentTime }}, are they what you expect? Maybe a timezone difference? – Brad Bell Nov 30 '16 at 20:48
1

the error was with the date format in the date comparison conditional and the until tag instead of unless

{% if currentTime <= newsDate | date('c') %} {# those two dates were formated differentely #}
    {% set invalidate = newsDate.expiryDate | date('c') %}
{% else %}
    {% set invalidate = auffuehrung.konzertStartdate |date('c') %}
{% endif %}

{% cache until invalidate %} {# not unless #}
 {# blablabla #}
{% endcache %}

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.