Shopware 6: Twig files not loaded when using sw_include

Viewed 2080

currently I'm struggeling with my theme for Shopwre 6. In Version 6.2.2 my theme breaks and won't load any includes twig files.

Following code is in my base.html.twig file of my theme.

{% block base_header %}
    <header class="header-main">
        {% block base_header_inner %}
            <div class="container">
                {% sw_include '@Themename/storefront/layout/header/header.html.twig' %}
            </div>
        {% endblock %}
    </header>
{% endblock %}

With this notation nothing loads. Replacing sw_extends with extends, loads the file.

In Version 6.1.6 it was working, but not in current 6.2.2. In my theme.json my view looks the following:

"views": [
     "@Storefront",
     "@Plugins",
     "@Themename"
  ],

Thanks for your help and advice.

Marcus

1 Answers

I have tested a little bit and It seems that this is a naming conflict. Because the name of the custom layout/header/header.html.twig is the same as in the core theme it gets overwritten and included at the same time. When I create a file with the same name under the same directory it will override the core file by default. And in the example it's also included by another custom template. However when I rename it to e.g. "custom-header" and include it as "custom-header" it works.

When the custom theme's "header.html.twig" is extending the core "header.html.twig" it would also be possible to not include this at all. Because the base_header block in the example above looks basically the same in the core template. The header can be overwritten by adding a layout/header/header.html.twig in the custom theme. The include of the header itself is already happening in the core "base.html.twig"

Related