# Produktvergleich Twig Bilder 2 - 4 (pad/auffüllen)

**URL:** <https://forum.shopware.com/t/produktvergleich-twig-bilder-2-4-pad-auffuellen/105958>\
**Category:** Shopware 6 (German)\
**Created:** [26. November 2024 um 16:25 UTC](https://forum.shopware.com/t/produktvergleich-twig-bilder-2-4-pad-auffuellen/105958 "2024-11-26T16:25:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [26. November 2024 um 16:25 UTC](https://forum.shopware.com/t/produktvergleich-twig-bilder-2-4-pad-auffuellen/105958/1 "2024-11-26T16:25:55Z")

</div>

Hallo. ich brauche für einen Produktvergleich 4 Bilder.  
1 cover bild und dann 3 weitere Produktbilder.  
Wie kann ich es auffüllen, so dass folgendes herauskommt.

```auto
"cover";"bild2";"bild3";""; oder
"cover";"";"";""; oder
.....?

```

Hier ist mein Twig:

```auto
"{% if product.cover is not null %}{{ product.cover.media.url }}{% endif %}";{#- -#}
{%- if product.media|length > 1 -%}
    {%- for mediaAssociation in product.media|slice(1,3) -%}
        "{{ mediaAssociation.media.url }}"
        {%- if not loop.last -%};{%- endif -%}
    {%- endfor -%}
{%- endif -%}{#- -#}

```

Danke und Gruss

---

<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:** [27. November 2024 um 07:15 UTC](https://forum.shopware.com/t/produktvergleich-twig-bilder-2-4-pad-auffuellen/105958/2 "2024-11-27T07:15:41Z")

</div>

Hey,

das sollte so funktionieren:

```auto
{% if page.product.cover is not null %}
    {{ page.product.cover.media.url }}
{% else %}
    "";
{% endif %}
{% if page.product.media|length > 1 %}
    {% for mediaAssociation in page.product.media|slice(1,3) %}
        {% if mediaAssociation.media.url %}
            {{ mediaAssociation.media.url }};
        {% else %}
            "";
        {% endif %}
    {% endfor %}
{% else %}
    {% for i in 0..2 %}
        "";
    {% endfor %}
{% endif %}

```

Berücksichtigt ist dabei, ob das Produkt mehr als 4 Bilder hat, das Produkt keine Bilder hat oder eben nur ein Bild hinterlegt ist.

Grüße

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [27. November 2024 um 13:24 UTC](https://forum.shopware.com/t/produktvergleich-twig-bilder-2-4-pad-auffuellen/105958/3 "2024-11-27T13:24:44Z")

</div>

Leider geht das nicht weil es nicht auffüllt.

Ich habe nur Frankenstein geschaffen:

```auto
{%-if product.media|length > 1 -%}
         {%- for mediaAssociation in product.media|slice(1,1) -%}
            {%- if mediaAssociation.media.url -%}
                "{{ mediaAssociation.media.url }}";
            {%- endif -%}
         {%- endfor -%}
    {%- else -%}
        "";
    {%- endif -%}
     {%-if product.media|length > 2 -%}
         {%- for mediaAssociation in product.media|slice(2,1) -%}
            {%- if mediaAssociation.media.url -%}
                "{{ mediaAssociation.media.url }}";
            {%- endif -%}
         {%- endfor -%}
     {%- else -%}
        "";
    {%- endif -%}
     {%-if product.media|length > 3 -%}
         {%- for mediaAssociation in product.media|slice(3,1) -%}
            {%- if mediaAssociation.media.url -%}
                "{{ mediaAssociation.media.url }}";
            {%- endif -%}
         {%- endfor -%}
    {%- else -%}
        "";     
    {%- endif -%}

```
