I have a listing page of entries, some of which may have future-dated postDates. I want to cache the output, but only until one of the pending entries goes live.
1 Answer
Easy! Get the most soonest upcoming pending entry, and use until
:
{% set firstPending = craft.entries({
section: 'articles',
status: 'pending',
order: 'postDate asc'
}).first %}
{% set cacheUntil = firstPending ? firstPending.postDate : now|date_modify('+1 year') %}
{% set content %}
{% cache until cacheUntil %}
...
{% endcache %}
{% endset %}
Note that this solution requires Craft 2.2.2598 or later.
-
Not sure if there's a way to include the
until
statement conditionally all-together, that way you wouldn't need to donow|date_modify('+1 year')
Sep 18, 2014 at 16:12 -
if craft.config.enableCache
is just a custom config var I'm using, doesn't have anything to do with the question. Sep 18, 2014 at 16:13 -
Just FYI... It's not necessary to specify "limit: 1" when you're using
.first
. Sep 18, 2014 at 16:29 -
-
Your original solution will work with a small tweak to the way cache clearing works in Craft. The next update will include that tweak. Oct 22, 2014 at 21:39