I'm trying to get pagination and cache to work together but it's failing.
Here's my current code:
{% cache globally using key
craft.request.path ~ '/p' ~ craft.request.getPageNum
for 2 hours %}
{% paginate topicEntries.limit(10)as pageInfo, topicEntries %}
{% for topic in topicEntries %}
more code here
{% endfor %}
{% endcache %
When I use this I get a template error that Variable pageInfo does not exist.
Then if I put the opening cache tag below the paginate tag. The first page shows 10 entries, but each page after that only displays 1 entry per page.
{% paginate topicEntries.limit(10)as pageInfo, topicEntries %}
{% cache globally using key
craft.request.path ~ '/p' ~ craft.request.getPageNum
for 2 hours %}
{% for topic in topicEntries %}
more code here
{% endfor %}
{% endcache %}
What I need to know is how to cache paginated entries so it's 10 per page and when a new entry is added the cache is cleared correctly.
Please advise.
{% paginate topicEntries.limit(10)as pageInfo, topicEntries %}
? If so, you're missing a space betweenlimit(10)
andas
. Guessing that's just an error here on SE, since that'd give you some other error. Also, I suspect that there are some code that accessespageInfo
that's outside of the code that's shown here? IfpageInfo
is created inside the cache tag, you can't access it outside. Seeing the rest of your template code would be useful.