Mahmoud Abdelsattar
Mahmoud Abdelsattar

Reputation: 1431

How to do a template multiple inheritance in Shopware 6?

I have two plugins:

  1. XYZ Plugin that is inheriting the Shopware base template/block and overriding it.
  2. ABC Plugin which I want to inherit XYZ overridden template/block and override it.

How can I do this in Shopware 6?

XYZ plugin code in tabs.html.twig file:

{% sw_extends '@Storefront/storefront/page/product-detail/tabs.html.twig' %}

{% block page_product_detail_tabs_inner %}
    <div class="detail-accordion" id="accordion">
        {% block page_product_detail_accordion_description %}
            <div class="card card-accordion card-accordion-description">
                {% block page_product_detail_accordion_description_header %}
                    {# My custom logic #}
                {% endblock %}
            </div>
        {% endblock %}
    </div>
{% endblock %}

ABC plugin code in tabs.html.twig file:

{% sw_extends '../../../../../../../XYZ/src/Resources/views/storefront/page/product-detail/tabs.html.twig' %}

{% block page_product_detail_tabs_inner %}
    {{ parent() }}
    <div class="detail-accordion" id="accordion">
        {% block page_product_detail_accordion_description %}
            <div class="card card-accordion card-accordion-description">
                {% block page_product_detail_accordion_description_header %}
                    {# My new custom logic to append #}
                {% endblock %}
            </div>
        {% endblock %}
    </div>
{% endblock %}

Unfortunately, this code is not working.

Upvotes: 3

Views: 2657

Answers (1)

Roman
Roman

Reputation: 2549

{% sw_extends '../../../../../../../XYZ/src/Resources/views/storefront/page/product-detail/tabs.html.twig' %}

this is wrong.

You have to extend @Storefront in both cases and make sure that you your plugins are loaded in the right sequence. So if you first load your plugin ABC then XYZ is automatically able to extend the template of ABC.

Updated answer Plugins are getting loaded in the order of the installation date (currently v6.4).

Upvotes: 4

Related Questions