Multiple Choice Filter

This filter is very similar to choice filter, but you can select multiple options. It groups values of a repository in a specified field and returns available options. If you select one or more of the options, multi choice filter will return item list filtered by the selected options.


Setting name Meaning
request_field Request field used to view the selected page. (e.g.
field Specifies the field in repository to apply this filter on. (e.g. item_color)
show_zero_choices Includes choices that have 0 documents in the choice array (defaults to false)
sort Choices can also be sorted. You can read more about this here.
tags Array of filter specific tags that will be accessible at Twig view data.


# app/config/config.yml
                - country
            repository: 'es.manager.default.product'
                request_field: 'country'
                field: country

Twig view data

View data returned by this filter to be used in template:

Method Value
getName() Filter name
getResetUrlParameters() Url parameters required to reset filter
getState() Filter state
getUrlParameters() Url parameters representing current filter state
getChoices() Returns a list of available choices
getTags() Lists all tags specified at filter configuration
hasTag($tag) Checks if filter has the specific tag

Each choice has its own data:

Method Value
isActive() Is this choice currently applied
isDefault() Is this choice the default one
getCount() Return the number of items for this choice
getLabel() Choice label
getUrlParameters() Returns a list of available choices

Usage in template example

This example uses filter defined in Search example. To display this filter we would add following code to template:

{% set choiceFilter = filter_manager.getFilters().color %}
    {% for choice in choiceFilter.getChoices() %}
            {% if choice.isActive() %}<b>{% endif %}
                <a href="{{ path(app.request.attributes.get('_route'), choice.getUrlParameters()) }}">
                    {{ choice.getLabel() }}</a>
                ({{ choice.getCount() }})
            {% if choice.isActive() %}</b>{% endif %}
    {% endfor %}
{% if choiceFilter.getState().isActive() %}
    <a href="{{ path(app.request.attributes.get('_route'), choiceFilter.getResetUrlParameters()) }}">
        Deactivate this filter
{% endif %}