Skip to content

Filter Options Horizontal

Availability:

  • Category list
  • Search results list
  • Promotion products list
  • New products list


Use filter_options_horizontal to render a list of available filters for a set of products.

Configuration parameters

shouldHideEmptySubcategories

number either 1 or 0. If set to 1 the empty subcategories in the categories filter will be hidden.

showSubcategoryCounters

number either 1 or 0. If set to 1 the counters of the categories filter will be shown.

showCounters

number either 1 or 0. If set to 1 the counters of all filters but categories will be shown.

shouldHideEmptyFilters

number either 1 or 0. If set to 1 the filters that are empty will be hidden.

Module source code

{% from "@macros/filters_horizontal.twig" import filters_horizontal %}
{% from "@macros/filters_subcategories.twig" import filters_subcategories %}

{% set filters = ObjectApi.getFilters() %}
{% set currency = ObjectApi.getShopCurrency() %}

{% set hasFilters = false %}
{% if filters.priceFilter or filters.producersFilter or filters.collectionsFilter or filters.optionsFilter|length > 0 or filters.attributesFilter|length > 0 or filters.availabilitiesFilter or filters.deliveriesFilter or filters.ratesFilter or filters.newsFilter or filters.promotionsFilter %}
    {% set hasFilters = true %}
{% endif %}

{% if filters.categoriesFilter and hasFilters  %}
    {% set hasFiltersAndSubcategories = true %}
{% elseif filters.categoriesFilter and not hasFilters %}
    {% set hasOnlySubcategories = true %}
{% else %}
    {% set hasOnlyFilter = true %}
{% endif %}

<s-filters>
    <filters-horizontal lazy>
        {{
            filters_subcategories(filters.categoriesFilter, moduleConfig|merge({
                instanceId: moduleInstance,
                hasFilters,
                hasFiltersAndSubcategories,
                hasOnlySubcategories,
                hasOnlyFilter
            }))
        }}

        {{
            filters_horizontal(filters, currency, moduleConfig|merge({
                instanceId: moduleInstance,
                categoryId: category_id,
                title,
                hasFilters,
                hasFiltersAndSubcategories,
                hasOnlySubcategories,
                hasOnlyFilter
            }))
        }}
    </filters-horizontal>
</s-filters>

Macros reference

Used Object Api methods

Module configuration schema

[
    {
        "state": "unfolded",
        "label": "General settings",
        "elements": [
            {
                "type": "infobox",
                "name": "infobox",
                "options": {
                    "type": "blank",
                    "message": "%s Related settings in the admin panel%s- selection of displayed filters in [the filter settings](%s)%s- changing phrases in [translations](%s)",
                    "placeholderValues": [
                        "####",
                        "\n",
                        "\/admin\/configFilters",
                        "\n",
                        "\/admin\/configLanguages"
                    ]
                }
            }
        ]
    },
    {
        "state": "unfolded",
        "label": "Subcategories",
        "elements": [
            {
                "type": "infobox",
                "name": "infobox-subcategories",
                "options": {
                    "type": "warning",
                    "message": "In the [filter settings](%s) the display of subcategories and the \"Count how many products subcategories have\" option must be enabled.",
                    "placeholderValues": [
                        "\/admin\/configFilters"
                    ]
                }
            },
            {
                "type": "checkbox",
                "name": "shouldHideEmptySubcategories",
                "label": "Hide empty subcategories",
                "defaultValue": 1
            },
            {
                "type": "checkbox",
                "name": "showSubcategoryCounters",
                "label": "Display the number of matches for each subcategory",
                "defaultValue": 1
            }
        ]
    },
    {
        "state": "unfolded",
        "label": "Filters",
        "elements": [
            {
                "type": "infobox",
                "name": "infobox-filters",
                "options": {
                    "type": "warning",
                    "message": "In the [filter settings](%s) option %sCount how many products match each option in the filter%s must be enabled.",
                    "placeholderValues": [
                        "\/admin\/configFilters",
                        "\"",
                        "\""
                    ]
                }
            },
            {
                "type": "checkbox",
                "name": "shouldHideEmptyFilters",
                "label": "Hide empty options in the filter",
                "defaultValue": 0
            },
            {
                "type": "checkbox",
                "name": "showCounters",
                "label": "Display the number of matches for each option in the filter",
                "defaultValue": 1,
                "hint": "Available for selected filters: collections, producers, attributes, variants."
            }
        ]
    }
]