Uncached Ditto call with pagination in cached document

How to achive cached document and uncached Ditto with pagination in MODX Evo.

Psst: since MODX Evolution 1.0.12 it is possible to cache document basing on $_GET parameters. You just need to enable it in System Configuration. Therefore, method described below works, but it is not an only and recommended solution anymore. I recommend enabling new MODX setting as it allows to cache whole page along with Ditto call with pagination.

It's a known problem - or maybe I should say difficulty - to have Ditto with pagination inside a document which have caching turned on.

"Why?" you may ask. When you have cached document with uncached Ditto call, pagination placeholders are lost because they are placed after Ditto call and become cached. That's why in normal scenario we need to have whole document uncached when using standard MODX snippet call. It isn't too efficent because all other snippets on page are also uncached.

MODX community created even a dedicated snippet to solve it. But there is a native MODX way to workaround this :)

Different snippet call

The way to have working uncached Ditto with pagination on a cached document is fairly simple. What you need to do is call Ditto other way then standard [ ! Ditto?... ! ] How to achive this? Via raw MODX API snippet call and that will be: $modx->runSnippet('Ditto',$params); Whats left is to construct simple snippet with it.

Snippet with Ditto

Our snippet (lets name it "run_ditto_articles") which will launch Ditto, should have parameters and pagination placeholders inside and it should look something close to this:

$params['tplPaginatePage']='@CODE: <a href="[ + url + ]">[ + page + ]</a> ';
$params['orderBy']='pub_date DESC';

$output = $modx->runSnippet('Ditto',$params);
$output .= '<p>Items: [ + total + ] Page: [ + pages + ]</p>';

return $output;

Now we need to place it in our document: [ ! run_ditto_articles ! ]

From this moment we will be able to have cached document & uncached Ditto with pagination. We can even make it more dynamic by adding parameters to it [ ! run_ditto_articles?parents=`[ * id * ]` ! ] and changing $params['parents']='5'; to $params['parents']=$parents; in snippet code.

Simple, isn't it? And in my opinion this is the best way to run snippets, because of rich customization options.

Tags: code, ditto, evo, modx, snippet