2

How can I cache an entry, lets say a product card but exclude an dynamic part? Like amount of favorites / Or link to add or remove to favorite.

{% set item = craft.shortlist.item(entry.id) %}

{% cache globally using key "product-card-" ~ entry.id until entry.dateUpdated %}

   ...

   {{ entry.title }}

   ...

   // EXCLUDE THIS PART FROM CACHE
   {% if item.inList %}
        <a class="love animating fav" href="{{ item.removeActionUrl }}" data-id="{{ entry.id }}"><i class="icon icon-heart"></i></a>
    {% else %}
        <a class="love animating" href="{{ item.addActionUrl }}" data-id="{{ entry.id }}"><i class="icon icon-heart"></i></a>
    {% endif %}

{% endcache %}

In EE CE Cache there you had {exp:ce_cache:escape}. How can I do this in Craft?

Made a feature request for escaping parts of cache for dynamic data.

http://feedback.buildwithcraft.com/forums/285221-feature-requests/suggestions/7412950-exclude-cache-for-dynamic-data

PLEASE VOTE :-)

2

You would simply not wrap it in cache tags. I don't think there's anything like that EE function to specifically exclude parts within the tag. Might be worth a feature request though?

{% set item = craft.shortlist.item(entry.id) %}

{% cache globally using key "product-card-" ~ entry.id ~ "-1" until entry.dateUpdated %}

    {{ entry.title }}

    ...

{% endcache %}

// EXCLUDE THIS PART FROM CACHE
{% if item.inList %}
    <a class="love animating fav" href="{{ item.removeActionUrl }}" data-id="{{ entry.id }}"><i class="icon icon-heart"></i></a>
{% else %}
    <a class="love animating" href="{{ item.addActionUrl }}" data-id="{{ entry.id }}"><i class="icon icon-heart"></i></a>
{% endif %}

{% cache globally using key "product-card-" ~ entry.id ~ "-2" until entry.dateUpdated %}

    ...

{% endcache %}
|improve this answer|||||
  • Doesn't work. It's repeating the cached content in the 2nd part. – Johannes Lamers Apr 1 '15 at 17:22
  • Sorry, I overlooked that you're using custom keys. These need to be unique, so you have to add unique string to the key for each caching block. – carlcs Apr 1 '15 at 17:26
  • Ok. that's what i was thinking. But you then end up with a lots of Cached content per entry. Let say you have some more dynamic data. All the cached content gets cluttered in the DB. I've posted a feature request to escape some parts of the cache tough. – Johannes Lamers Apr 1 '15 at 17:28
  • 2
    Made a feature request for escaping parts of cache for dynamic data. feedback.buildwithcraft.com/forums/285221-feature-requests/… – Johannes Lamers Apr 1 '15 at 17:30
  • 1
    Just saw this (I'm the dev for Shortlist) - right now the best option I've seen is to do as @carlcs did and escape the specific dynamic block. I've looked into alternatives and right now, this seems the only way – Joel Bradbury Apr 10 '15 at 9:15

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.