如何在 Shopware 6 中进行模板多重继承? [英] How to do a template multiple inheritance in Shopware 6?

查看:29
本文介绍了如何在 Shopware 6 中进行模板多重继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个插件:

  1. 继承 Shopware 基础模板/块的 XYZ 插件和覆盖它.
  2. 我想继承 XYZ 覆盖的模板/块的 ABC 插件和覆盖它.

如何在 Shopware 6 中执行此操作?

tabs.html.twig 文件中的

XYZ 插件代码:

{% sw_extends '@Storefront/storefront/page/product-detail/tabs.html.twig' %}{% 阻止 page_product_detail_tabs_inner %}<div class="detail-accordion";id=手风琴">{% 阻止 page_product_detail_accordion_description %}<div class="card card-accordion card-accordion-description">{% 阻止 page_product_detail_accordion_description_header %}{# 我的自定义逻辑 #}{% 结束块 %}

{% 结束块 %}

{% 结束块 %}

tabs.html.twig 文件中的 ABC 插件代码:

{% sw_extends '../../../../../../../XYZ/src/Resources/views/storefront/page/product-detail/tabs.html.twig' %}{% 阻止 page_product_detail_tabs_inner %}{{ 父母()}}<div class="detail-accordion";id=手风琴">{% 阻止 page_product_detail_accordion_description %}<div class="card card-accordion card-accordion-description">{% 阻止 page_product_detail_accordion_description_header %}{# 我要追加的新自定义逻辑 #}{% 结束块 %}

{% 结束块 %}

{% 结束块 %}

很遗憾,此代码不起作用.

解决方案

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

这是错误的.

在这两种情况下,您都必须扩展 @Storefront 并确保您的插件以正确的顺序加载.所以如果你首先加载你的插件 ABC 那么 XYZ 会自动扩展 ABC 的模板.

更新答案插件按安装日期的顺序加载(当前为 v6.4).

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.

解决方案

{% 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).

这篇关于如何在 Shopware 6 中进行模板多重继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆