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

mFilterSelected ​

Snippet for displaying selected (active) filters with the ability to remove them.

Description ​

mFilterSelected shows a block with current active filters. The user can remove individual filters or reset all at once. The component integrates with JavaScript for live updates during AJAX filtering.

Features:

  • Grouping by filter key
  • Automatic labels from lexicons and configuration
  • Reset-all button
  • Integration with SelectedFilters JS component
  • SEO URL and plain GET parameter support

Parameters ​

Main ​

ParameterDefaultDescription
resourceIdcurrent resourceResource ID for filter configuration

Templates ​

ParameterDefaultDescription
tplOutermfilter.selected.outerOuter container
tplGroupmfilter.selected.groupGroup template (for grouping by filterKey)
tplItemmfilter.selected.itemSingle filter item template
tplResetmfilter.selected.resetReset button template

Behavior ​

ParameterDefaultDescription
groupedtrueGroup items by filter key
showLabelstrueShow filter labels (Color:, Size:)
showResettrueShow "Reset all" button
hideWhenEmptytrueHide block when no filters selected
resetTextfrom lexiconReset button text

Output ​

ParameterDefaultDescription
toPlaceholder—Output to placeholder

Placeholders in templates ​

tplOuter ​

PlaceholderDescription
{$items}HTML of all items/groups
{$reset}HTML of reset button
{$count}Number of active filters
{$empty}true if no filters selected
{$hidden}true if block should be hidden
{$filterLabels}JSON object of labels for JS

tplGroup ​

PlaceholderDescription
{$key}Filter key
{$label}Filter label
{$items}HTML of group items
{$count}Number of values in group
{$showLabel}Whether to show label

tplItem ​

PlaceholderDescription
{$key}Filter key
{$value}Filter value
{$filterLabel}Filter label
{$valueLabel}Value label
{$label}Alias for valueLabel

tplReset ​

PlaceholderDescription
{$text}Button text

Examples ​

Basic call ​

fenom
{'!mFilterSelected' | snippet}

Without grouping ​

fenom
{'!mFilterSelected' | snippet: [
    'grouped' => false
]}

Without labels and reset button ​

fenom
{'!mFilterSelected' | snippet: [
    'showLabels' => false,
    'showReset' => false
]}

Custom reset text ​

fenom
{'!mFilterSelected' | snippet: [
    'resetText' => 'Clear filters'
]}

Custom templates ​

fenom
{'!mFilterSelected' | snippet: [
    'tplOuter' => '@INLINE
        <div class="selected-filters" data-mfilter-selected>
            {$items}
            {$reset}
        </div>',
    'tplItem' => '@INLINE
        <span class="filter-tag" data-mfilter-remove="{$key}" data-value="{$value}">
            {$label} <button type="button">&times;</button>
        </span>',
    'tplReset' => '@INLINE
        <button type="button" data-mfilter-reset class="btn btn-link">{$text}</button>'
]}

Integration with form ​

Recommended to place above filter results:

fenom
<div class="catalog">
    <aside class="catalog-sidebar">
        {'!mFilterForm' | snippet}
    </aside>

    <main class="catalog-content">
        {* Selected filters *}
        {'!mFilterSelected' | snippet}

        {* Results *}
        {'!mFilter' | snippet: [
            'element' => 'msProducts',
            'paginator' => 'pdoPage',
            'parents' => $_modx->resource.id
        ]}
    </main>
</div>

JavaScript integration ​

The block updates automatically on AJAX filtering via the SelectedFilters JS component.

Data attributes ​

AttributeDescription
data-mfilter-selectedSelected filters container
data-mfilter-remove="{key}"Remove value button
data-value="{value}"Value to remove
data-mfilter-resetReset all filters button

Example HTML markup ​

html
<div class="selected-filters" data-mfilter-selected>
    <div class="filter-group">
        <span class="filter-label">Color:</span>
        <span class="filter-tag" data-mfilter-remove="color" data-value="red">
            Red <button>&times;</button>
        </span>
        <span class="filter-tag" data-mfilter-remove="color" data-value="blue">
            Blue <button>&times;</button>
        </span>
    </div>
    <button data-mfilter-reset>Reset all</button>
</div>

Default chunks ​

mfilter.selected.outer ​

html
<div class="mfilter-selected{if $hidden} mfilter-selected--hidden{/if}"
     data-mfilter-selected
     data-filter-labels='{$filterLabels}'>
    {if !$empty}
        <div class="mfilter-selected__items">
            {$items}
        </div>
        {$reset}
    {/if}
</div>

mfilter.selected.item ​

html
<span class="mfilter-selected__tag"
      data-mfilter-remove="{$key}"
      data-value="{$value}">
    {$label}
    <button type="button" class="mfilter-selected__remove" aria-label="Remove">&times;</button>
</span>

mfilter.selected.reset ​

html
<button type="button" class="mfilter-selected__reset" data-mfilter-reset>
    {$text}
</button>