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

mFilter

Main snippet for outputting filtered results.

Parameters

Element/Paginator mode

ParameterDefaultDescription
elementSnippet for data (msProducts, pdoResources, getTickets)
paginatorpdoPagePagination snippet
lexiconsExtra 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)
whereExtra conditions (JSON)
selectFields to select (JSON)

Templates

ParameterDefaultDescription
tplmfilter.rowSingle result row template
tplOutermfilter.outerOuter wrapper template
tplEmptyTemplate for empty results
tplPaginationmfilter.paginationPagination template
tplsJSON with alternate templates for view switching

TV and fields

ParameterDefaultDescription
includeTVsfalseInclude TVs in results
processTVsTV 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