John Davidson

php - How to do a template multiple inheritance in Shopware 6?

0 comments
Message:


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.



My Answer:
In Shopware 6, you can achieve template multiple inheritance by using the `{% sw_extends %}` tag to extend a template from another plugin. However, in your case, it seems like the path you are using in the `{% sw_extends %}` tag is incorrect.

To fix this issue, you need to make sure that you are providing the correct path to the template file you want to extend. Here is how you can update your ABC plugin code in tabs.html.twig file:

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

{% block page_product_detail_tabs_inner %}
{{ parent() }}

{% block page_product_detail_accordion_description %}

{% block page_product_detail_accordion_description_header %}
{# My new custom logic to append #}
{% endblock %}

{% endblock %}

{% endblock %}


Make sure to replace `@XYZ` with the correct namespace of the XYZ plugin. This should allow your ABC plugin to inherit the overridden template from the XYZ plugin and add its own custom logic.

Additionally, ensure that both plugins are properly installed and activated in your Shopware 6 installation. If you continue to experience issues, you may need to clear the cache and recompile the theme to see the changes reflected on the storefront.

Rate this post

4 of 5 based on 9174 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us