pdoResources limit vs total


I’m unsure if this is a bug or intended behavior but seems a bit weird. When using pdoResources I am fetching a list of entries under a specific container. My container has 8 resources. When &limit=0 and I output to [[+total]] variable, it correctly tells me that I have 8 resources in my result set. However, if I specify a limit, ex: &limit=4 then sure enough, my results are now 4 resources but the [[+total]] variable is still 8.

I am guessing this makes sense as there are still 8 resources found but I am limitting the output to only 4 but reading the documentation on the total variable it reads: “Name of the placeholder for storing the total number of results.” and in the case of &setTotal “Indicates if the total placeholder should be populated with a count of the results.”, so I am expecting [[+total]] to tell me the number of entries in the result that is being output and not what the logic is matching.

In any case, I don’t seem to have a way to get the total number of entries that would be output (when a limit is assigned) that I can see without some custom coding and I feel there should be a variable that does this without customization.

Am I missing something obvious?

Step to reproduce

Try the call with &limit=0 and a &limit=`` that is less than the actual number of entries and you’ll see that the total variable expresses the number of matched entries and not the actual number of entries in the result.


This is on MODX Cloud running 3.0.2-pl


that’s intended. total is allways the total number of matching items.
I don’t think, there is a placeholder, which holds the counted items.

The total placeholder is generally used for the paging.
It allows snippets like pdoPage/getPage to generate the correct page navigation.

Pagination makes a ton of sense, I can see that being solid reasoning behind it.

I guess what I am missing in this case is a variable that would actually give me the output count. I was thinking just having the same value as &limit to be available as a placeholder so I could take the value from there but then realized just because I set a limit of 4 it doesn’t mean it will output 4 if there is less than that.

So I am now trying to figure out the optimal way to actually “count” the returned result set (output) as a number. I might need a snippet which wraps around the pdoResources call, capture the output so I can do the relevant processing and then return the end result + my processed variables.

I’m wondering if there is another way around it I might be overlooking? in any case, once I sort something out I’ll update here in case someone else finds it useful.

maybe, you could duplicate the pdoResources snippet and get the count
after pdoTools/snippet.pdoresources.php at 04d63ab22dc34a85ee684fc6f0062bedde5cf890 · modx-pro/pdoTools · GitHub


$count = $pdoFetch->count;
$modx->setPlaceholder('count', $count);