# Twig Variable als Block-Name

**URL:** https://forum.shopware.com/t/twig-variable-als-block-name/67092
**Category:** Themes & Design
**Created:** [20. Mai 2020 um 14:11 UTC](https://forum.shopware.com/t/twig-variable-als-block-name/67092 "2020-05-20T14:11:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![inventivo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/inventivo/32/11397_2.png) [@inventivo](https://forum.shopware.com/u/inventivo)
#### Post date: [20. Mai 2020 um 14:11 UTC](https://forum.shopware.com/t/twig-variable-als-block-name/67092/1 "2020-05-20T14:11:51Z")

</div>

Weiß jemand einen Weg, wie man eine Variable für einen Block-Namen nutzen kann?

So funktioniert es nicht:

{%set&nbsp;MyVariable = ‘page\_product\_detail\_cross\_selling\_custom\_name’

{% block MyVariable %}  
…  
{% endblock %}

&nbsp;

---

<div class="post-metadata">

### Author: ![NextMike](https://avatars.discourse-cdn.com/v4/letter/n/838e76/32.png) [@NextMike](https://forum.shopware.com/u/NextMike)
#### Post date: [21. Mai 2020 um 16:27 UTC](https://forum.shopware.com/t/twig-variable-als-block-name/67092/2 "2020-05-21T16:27:11Z")

</div>

Schreib mal wofür, vielleicht gibt es auch andere Ansätze.

---

<div class="post-metadata">

### Author: ![inventivo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/inventivo/32/11397_2.png) [@inventivo](https://forum.shopware.com/u/inventivo)
#### Post date: [22. Mai 2020 um 07:14 UTC](https://forum.shopware.com/t/twig-variable-als-block-name/67092/3 "2020-05-22T07:14:48Z")

</div>

Aus einer Plugin-Konfiguration heraus möchte ich einen Custom Block in ein text-field eingeben lassen, wenn die Standard-Blöcke für die Anzeige von Code in einem Block nicht verwendet werden sollen.

---

<div class="post-metadata">

### Author: ![ShapeAndShift](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@ShapeAndShift](https://forum.shopware.com/u/ShapeAndShift)
#### Post date: [22. Mai 2020 um 07:21 UTC](https://forum.shopware.com/t/twig-variable-als-block-name/67092/4 "2020-05-22T07:21:30Z")

</div>

Verstehe noch nicht so ganz was du meinst 😃

Aber wenn du irgendeinen Code in der Storefront nicht anzeigen lassen möchtest oder eben einen custom code anstatt des default blocks, dann machste das mit nen simplen if.

Also: bool Field in der Plugin Config und dann im Template:

```
{% block page_product_detail_cross_selling %}
   {% if plugin.config.bool %}
        custom code
    {% else %}
        {{ parent() }}
    {% endif %}
{% endblock %}

```

&nbsp;

---

<div class="post-metadata">

### Author: ![inventivo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/inventivo/32/11397_2.png) [@inventivo](https://forum.shopware.com/u/inventivo)
#### Post date: [24. Mai 2020 um 15:56 UTC](https://forum.shopware.com/t/twig-variable-als-block-name/67092/5 "2020-05-24T15:56:32Z")

</div>

Der Merchant bzw. sein Developer sollen in ein Plugin Config Textfeld einen Blocknamen eingeben können (etwa ein SW unbekannter Block aus einem anderen Plugin). In diesem Block wird dann der Plugin Code geladen. Dafür benötige ich einen Block mit dynamischem Namen, der aus der Plugin Config kommt.
