pdoResources count not working

I’m trying to set a dynamic class when the total count of items in a pdoResources query exceeds a certain number. Normally on this slider i’m using the pagination buttons below it are hidden, but when the count is greater than 4, then buttons appear. I’m trying to adjust the height of the colored background of a similar slider using the same method by adding a class. But it’s not working for some reson.

I have the &setTotal set to 1 and &totalVar set to featInsightsTotal in my pdoResources query.

in my classes I have this: [[+featInsightsTotal:lt=5:then=noDeskPagination:else=``]]

I would think that when the total is less than 5, it’d use the class and when it is 5+ it wouldn’t. But for some reason it is using the class.

What is setting that placeholder, and are you sure it’s set before that tag is processed?

This is the order that it is written in:

    &where=`[{"publishedon:>=":"[[!getDate? &offset=`-12 month`]]"}]`

Then in my <div> i have this:

<div class="row slider-row [[+featInsightsTotal:lt=`5`:then=`noDeskPagination`:else=``]]">

I know that it’s reading the count properly because [[+featInsightsTotal]] by itself is returning 5 and when I remove an event from the list, it reads as 4.

So where exactly do you output the [[+featInsightsTotal]] placeholder? Inside the chunk “featInsights”?

BTW: If you are using getDate uncached for the &where property, then you have to call pdoResources also uncached.

1 Like

It’s in both the tpl and the div that I have just beneath it.

That’s all it was too. It was the getDate issue.

I’ve never really understood the differences between cached and uncached snippets. I haven’t found an explanation that makes sense.

A cached snippet is only executed once.
When the cache is empty and someone makes a request to a resource, the cached snippets are executed and their result is written to the cache. All future requests return the same result, until the cache is cleared again.

An uncached snippet on the other hand is executed on every request.

Every time you change a resource or chunk or snippet etc. in the manager and click the “Save” button, the cache is cleared.

You need uncached snippets for example to handle user data. Let’s say you have a contact form on your page. The snippet that processes the sent form data has to be uncached, because the data is unique for every request.

If you have a page where the displayed data depends on the current time, then you have to use uncached snippets as well. Otherwise the displayed data stays the same, until the cache is cleared again.


That was the clearest explanation of MODX snippet caching I’ve ever read. Would be great to put it in the docs…

1 Like

I agree, that was an excellent explanation! Thank you very much!

Another point on uncached tags: Using the exclamation point can cause a delay in processing the tag. So an uncached tag inside an cached tag or page means that the results of the uncached tag may not be available when they’re needed.

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.