# Filter ausblenden, der nur einen Wert hat

**URL:** <https://forum.shopware.com/t/filter-ausblenden-der-nur-einen-wert-hat/103373>\
**Category:** Shopware 6 (German)\
**Tags:** general, programming, twig\
**Created:** [19. März 2024 um 21:14 UTC](https://forum.shopware.com/t/filter-ausblenden-der-nur-einen-wert-hat/103373 "2024-03-19T21:14:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![owy](https://avatars.discourse-cdn.com/v4/letter/o/b38774/32.png) [@owy](https://forum.shopware.com/u/owy)\
**Post date:** [19. März 2024 um 21:14 UTC](https://forum.shopware.com/t/filter-ausblenden-der-nur-einen-wert-hat/103373/1 "2024-03-19T21:14:30Z")

</div>

In filter-panel.html.twig hat Shopware folgenden Code, der die Filter-Optionen auflistet:

[…]

```auto
                        {% block component_filter_panel_item_properties %}
                            {# @var properties \Shopware\Core\Framework\DataAbstractionLayer\Search\AggregationResult\Metric\EntityResult #}
                            {% set properties = listing.aggregations.get('properties') %}

                            {% if not properties.entities is empty %}
                                {% for property in properties.entities %}
                                    {% sw_include '@Storefront/storefront/component/listing/filter/filter-property-select.html.twig' with {
                                        elements: property.options,
                                        sidebar: sidebar,
                                        name: 'properties',
                                        displayName: property.translated.name,
                                        displayType: property.displayType,
                                        pluginSelector: 'filter-property-select',
                                        propertyName: property.translated.name
                                    } %}
                                {% endfor %}
                            {% endif %}
                        {% endblock %}

```

[…]

Nun dachte ich mir, dass ich statt dem ‚non… empty‘ check, einfach ‚|length \>1‘ oder ‚.count() \>1‘ verwende. Aber beides scheint nicht zu funktionieren…

Wie kann ich feststellen, ob 2 oder mehr Elemente vorhanden sind (statt nur empty true/false)?

---

<div class="post-metadata">

**Author:** ![abdullah](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@abdullah](https://forum.shopware.com/u/abdullah)\
**Post date:** [19. März 2024 um 23:26 UTC](https://forum.shopware.com/t/filter-ausblenden-der-nur-einen-wert-hat/103373/2 "2024-03-19T23:26:12Z")

</div>

Wenn ich mich richtig erinnere, werden die Filter per JavaScript neu geladen/gesetzt. Daher könnte deine Änderung keinen Effekt haben.

Eventuell müsstest du das JavaScript ebenfalls anpassen z. B. hier: [shopware/src/Storefront/Resources/app/storefront/src/plugin/listing/filter-property-select.plugin.js at 0ef0cc6ecfe48c60cb9c9a3cb8543f79068a6211 · shopware/shopware · GitHub](https://github.com/shopware/shopware/blob/0ef0cc6ecfe48c60cb9c9a3cb8543f79068a6211/src/Storefront/Resources/app/storefront/src/plugin/listing/filter-property-select.plugin.js#L70)

---

<div class="post-metadata">

**Author:** ![MrAle](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@MrAle](https://forum.shopware.com/u/MrAle)\
**Post date:** [20. März 2024 um 07:25 UTC](https://forum.shopware.com/t/filter-ausblenden-der-nur-einen-wert-hat/103373/3 "2024-03-20T07:25:02Z")

</div>

Hey,

was du vorhast sollte schon so funktionieren.  
Probiers mal mit `{% if properties.entities.elements|length>1 %}`

Grüße

---

<div class="post-metadata">

**Author:** ![owy](https://avatars.discourse-cdn.com/v4/letter/o/b38774/32.png) [@owy](https://forum.shopware.com/u/owy)\
**Post date:** [20. März 2024 um 07:51 UTC](https://forum.shopware.com/t/filter-ausblenden-der-nur-einen-wert-hat/103373/4 "2024-03-20T07:51:16Z")

</div>

Danke für eure Inputs. Konnte es nun lösen - der Denkfehler war, dass ich eine Ebene zu „früh“ geprüft habe, statt erst auf Element-Ebene:

```auto
{% if not properties.entities is empty %}
                                {% for property in properties.entities %}
                                	{% if property.options|length > 1 %}
                                    	{% sw_include '@Storefront/storefront/component/listing/filter/filter-property-select.html.twig' with {
                                        	elements: property.options,
                                        	sidebar: sidebar,
                                        	name: 'properties',
                                        	displayName: property.translated.name,
                                        	displayType: property.displayType,
                                        	pluginSelector: 'filter-property-select',
                                        	propertyName: property.translated.name
                                    	} %}
                                    {% endif %}
                                {% endfor %}
                            {% endif %}

```

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/2/9/29c7587ba660f00e4995d1743162782e5d6d8653.svg) [@system](https://forum.shopware.com/u/system)\
**Post date:** [19. April 2024 um 07:51 UTC](https://forum.shopware.com/t/filter-ausblenden-der-nur-einen-wert-hat/103373/5 "2024-04-19T07:51:28Z")

</div>

Dieses Thema wurde automatisch 30 Tage nach der letzten Antwort geschlossen. Es sind keine neuen Antworten mehr erlaubt.
