Ditto’s filter excludes documents from the final dataset by a specific criterion. Multiple filter clauses are joined with logical OR operator so we are left within the final dataset with documents that meet NOT(criterion-1) AND NOT(criterion-2) ... AND NOT(criterion-N).
But what to do if we need to obtain documents meeting criterion-1 OR criterion-2 ... OR criterion-N?
The following is my solution based on PHx (luckily, Ditto snippet supports it by default).
Suppose, we need to obtain documents whose pagetitle contains „MODx” or whose firstname template variable contains „Joe”.
Ditto call
[[Ditto? &parents=`3,4,5` &display=`all` &tpl=`or-clause`]]
Chunk „or-clause”
[+phx:if=`[+pagetitle:contains=`MODx`+][+firstname:contains=`Joe`+]`:is=`00`:then=``:else=`{{chunk-to-display-doc}}`+]
We need custom PHx modifier „contains” — it should be implemented as a snippet named „phx:contains”.
Snippet „phx:contains”
<?php return strpos($output, $options) === FALSE ? '0' : '1'; ?>
How it works? The „contains” modifier transforms placeholder into 1 or 0 depending on whether it contains requested text or not. The „if” statement concatenates both transformed placeholders pagetitle and firstname — if it appears to be „00” (neither pagetitle contains „MODx” nor firstname contains „Joe”) no output is produced, otherwise (at least one condition is satisfied) regular output is rendered.
- Required fields are marked with *.
- Comments are published after the approval of the site moderator, who is a human rather than a wind-fast computer program so please be patient. Off-topic comments are definitely removed.
| Enter this code into the appropriate field of the form while submitting an e-mail or a comment. If you have trouble with reading it, generate another... |


