0

Im using a pretty standard method for calling for entries, but with one small caveat in that I'm setting the limit inside a variable which is passed through to an include

so my index.twig file is like so

{% include 'homepage/_latest' with {'postCount' : 9} %}

and my homepage/_latest file has the following

{% cache %}
{% set latest = craft.entries.section('blog').limit(postCount ? postCount : 12) %}

<div class="entries entries--latest">

    {% for entry in latest %}

    {% include 'blocks/_entry-item-latest' %}

    {% endfor %}

</div>

{% endcache %}

Is that variable the issue for me/ I save a post and it doesnt know up on the homepage. I had it setup to invalidate every 15 minutes, but we put out 3-4 posts a day so theres no real need to invalidate that content every 15 minutes

  • I'm pretty sure that wouldn't affect it. What happens if you remove it as a test. – Brad Bell Nov 20 '14 at 21:18
2

If I understand you correctly, you’d basically need it to store separate caches depending on the limit.

The way to do that would be to set a custom key on the {% cache %} tag with the using key param:

{% if postCount is not defined or not postCount %}
    {% set postCount = 12 %}
{% endif %}

{% cache using key "homepage/_latest:"~postCount %}
    {% set latest = craft.entries.section('blog').limit(postCount) %}
    ...
{% 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.