Blog Sections Open

Combining Multiple TV Filters in Ditto

This legacy question started with a Ditto filter built from one TV value: $filter = ''; if (isset($_GET['id']) && $_GET['id'] != 'all') { $filter = 'emkost,' . $_GET['id'] . ',7'; } echo $modx->runSnippet('Dit

This legacy question started with a Ditto filter built from one TV value:

$filter = '';
if (isset($_GET['id']) && $_GET['id'] != 'all') {
    $filter = 'emkost,' . $_GET['id'] . ',7';
}

echo $modx->runSnippet('Ditto', array(
    'startID' => $modx->documentIdentifier,
    'tpl' => 'akk_price',
    'paginate' => '1',
    'display' => '20',
    'filter' => $filter,
));

The next requirement was to match another TV as well, for example:

$filter = 'emkost,' . $_GET['id'] . ',7' . '|' . 'europa,' . $_GET['id'] . ',7';

Main Idea

If the filter syntax supports the pipe separator as an OR condition in your Ditto setup, this approach is fine. The important part is to keep the generated filter string readable and predictable.

Good Practice

  • build the filter in PHP before calling Ditto
  • validate $_GET values before using them
  • keep the TV names explicit instead of hiding them in long inline calls
  • test both the single-condition and multi-condition branches

When to Refactor Further

If the number of filter branches grows, move the logic into a dedicated helper snippet. Ditto calls stay easier to read, and the filtering rules become simpler to maintain.

Newer post

Showing the First EvoGallery Image on a Listing Card

How to display only the first EvoGallery image for a resource when rendering product or listing cards in Evolution CMS.

Older post

Grouping getResources Output by Publication Date

A practical pattern for grouping getResources or pdoResources output into year and month blocks instead of one flat chronological list.