Skip to content
mFilter
mFilter
Faceted filtering for MODX 3 with SEO URL support
  • MODX 3
  • PHP 8.1
  • Vue 3
  1. Extras
  2. mFilter
  3. Snippets
  4. mFilter

mFilter ​

Main snippet for outputting filtered results.

Parameters ​

Element/Paginator mode ​

ParameterDefaultDescription
element—Snippet for data (msProducts, pdoResources, getTickets)
paginatorpdoPagePagination snippet
lexicons—Extra lexicons to load (comma-separated)

Data selection ​

ParameterDefaultDescription
parentscurrent resourceParent resource IDs (comma-separated)
depth10Depth for child categories
limit20Items per page
offset0Starting offset
sortbypagetitleSort field
sortdirASCSort direction (ASC, DESC)
where—Extra conditions (JSON)
select—Fields to select (JSON)

Templates ​

ParameterDefaultDescription
tplmfilter.rowSingle result row template
tplOutermfilter.outerOuter wrapper template
tplEmpty—Template for empty results
tplPaginationmfilter.paginationPagination template
tpls—JSON with alternate templates for view switching

TV and fields ​

ParameterDefaultDescription
includeTVsfalseInclude TVs in results
processTVs—TV names to process (comma-separated)

Display ​

ParameterDefaultDescription
showHiddenfalseShow hidden resources
showUnpublishedfalseShow unpublished
showDeletedfalseShow deleted

AJAX ​

ParameterDefaultDescription
ajaxfalseReturn JSON for AJAX requests
ajaxModefullAJAX mode: results, suggestions, full

Pagination ​

ParameterDefaultDescription
pageParampageGET parameter name for page
totalVarmfilter.totalPlaceholder for total count
pageCountVarmfilter.pageCountPlaceholder for page count

Output ​

ParameterDefaultDescription
toPlaceholdersfalseOutput results to placeholders
outputSeparator\nSeparator between rows

Examples ​

Basic call with MiniShop3 ​

fenom
{'!mFilter' | snippet: [
    'element' => 'msProducts',
    'paginator' => 'pdoPage',
    'parents' => $_modx->resource.id,
    'limit' => 24,
    'tpl' => 'mfilter.row'
]}

With pdoResources (without MS3) ​

fenom
{'!mFilter' | snippet: [
    'element' => 'pdoResources',
    'paginator' => 'pdoPage',
    'parents' => $_modx->resource.id,
    'includeTVs' => 'image,price',
    'limit' => 20,
    'tpl' => 'catalog.row'
]}

View toggle (grid/list) ​

fenom
{* Toggle buttons *}
<div class="view-toggle">
    <a href="?tpl=grid" data-mfilter-tpl="grid">Grid</a>
    <a href="?tpl=list" data-mfilter-tpl="list">List</a>
</div>

{'!mFilter' | snippet: [
    'element' => 'msProducts',
    'paginator' => 'pdoPage',
    'parents' => $_modx->resource.id,
    'tpl' => 'mfilter.grid',
    'tpls' => ['grid' => 'mfilter.grid', 'list' => 'mfilter.row']
]}

Sort from URL ​

Sort is taken from SEO URL or GET parameter sort:

/catalog/sort_price-asc/     → sort by price (ascending)
/catalog/?sort=price-desc   → sort by price (descending)
fenom
{* Sort dropdown *}
<select data-mfilter-sort>
    <option value="pagetitle-asc">By name</option>
    <option value="price-asc">Price: low to high</option>
    <option value="price-desc">Price: high to low</option>
    <option value="createdon-desc">Newest</option>
</select>

{'!mFilter' | snippet: [
    'element' => 'msProducts',
    'sortby' => 'pagetitle',
    'sortdir' => 'ASC'
]}

Limit from URL ​

/catalog/limit_48/           → 48 products per page
/catalog/?limit=96           → 96 products per page
fenom
<select data-mfilter-limit>
    <option value="24">24</option>
    <option value="48">48</option>
    <option value="96">96</option>
</select>

{'!mFilter' | snippet: [
    'element' => 'msProducts',
    'limit' => 24
]}

Extra conditions ​

fenom
{'!mFilter' | snippet: [
    'element' => 'msProducts',
    'parents' => $_modx->resource.id,
    'where' => ['Data.price:>' => 0, 'Data.favorite' => 1]
]}

Empty results ​

fenom
{'!mFilter' | snippet: [
    'element' => 'msProducts',
    'tplEmpty' => '@INLINE <p>No products found. Try changing the filter.</p>'
]}

Legacy mode (no element) ​

fenom
{'!mFilter' | snippet: [
    'parents' => $_modx->resource.id,
    'class' => 'msProduct',
    'sortby' => 'pagetitle',
    'limit' => 20,
    'tpl' => 'msProducts.row',
    'includeTVs' => 'image'
]}

Placeholders ​

After the snippet runs, these placeholders are available:

PlaceholderDescription
[[+mfilter.total]]Total result count
[[+mfilter.pageCount]]Page count
[[+mfilter.page]]Current page
[[+mfilter.limit]]Items per page
[[+mfilter.sort]]Current sort (price-asc)
[[+mfilter.sortBy]]Sort field (price)
[[+mfilter.sortDir]]Direction (asc)

For pdoPage pagination:

PlaceholderDescription
[[+page.nav]]Pagination HTML
[[+page.total]]Total items
[[+page.pages]]Total pages

mSearch integration ​

fenom
{'!mFilter' | snippet: [
    'element' => 'msProducts',
    'paginator' => 'pdoPage',
    'parents' => $_modx->resource.id,
    'search' => $_GET['mse_query']
]}

See: mSearch integration