inheritance of controller templates with custom theme not working properly
I have a strange behavior when I load a custom template inside a controller which extends a custom theme:
Controller loads a template: $this->renderStorefront('@Storefront/mycontroller/index.html.twig');.
The template extends the base.html.twig of a custom theme: {% sw_extends '@Storefront/storefront/base.html.twig' %}. The file only contains the sw_extends, nothing else.
The template of the custom theme changes some contents and extends the shopware theme: {% sw_extends '@Storefront/storefront/base.html.twig' %}
The page loads but it doesn’t display all the changes of the base.html.twig of the custom theme.
Hi Uli, can you please try to delete the cache directory (delete whole /var/cache Dir) per console and tell me if the changes of the custom theme are displayed after a reload?
We are aware of a current bug in the cache:clear command, that can result in this behaviour.
Greets, Stefan
Hi @ssltg,
I tried both, clear:cache and rm -rf /var/cache, both didn't help
Hi @uehler , can you please provide some more details? Maybe the contents of the different twig-files? Is the Theme associated with the saleschannel you are calling? Are no changes from the theme-template displayed or just some?
Hi @ssltg,
the theme is the theme of the current saleschannel. I stripped the html of the theme file, the plugin file is only contains the sw_extends
Themefile:
custom/plugins/CustomTheme/src/Resources/views/storefront/base.html.twig
{% sw_extends '@Storefront/storefront/base.html.twig' %}
{% block base_script_hmr_mode %}
{# some code #}
{% endblock %}
{% block base_navigation %}{% endblock %}
{% block base_header %}
{% sw_include '@Storefront/storefront/layout/header/top-bar.html.twig' %}
{% block base_header_inner %}
{% sw_include '@Storefront/storefront/layout/header/header.html.twig' %}
{% block base_navigation_flyout %}
{% sw_include '@Storefront/storefront/layout/navigation/navigation-flyout.html.twig' %}
{% endblock %}
{% sw_include '@Storefront/storefront/layout/header/top-bar.html.twig' %}
{% endblock %}
{% endblock %}
{% block base_footer_inner %}
{% sw_include '@Storefront/storefront/layout/footer/footer.html.twig' %}
{% endblock %}
Pluginfile:
custom/plugins/CustomPlugin/src/Resources/views/episerver/index.html.twig
{% sw_extends '@Storefront/storefront/base.html.twig' %}
The theme file empties the navigation block and includes the navigation in another block.
When I call my controller, which loads the plugin template, the navigation is duplicated, because the {% block base_navigation %}{% endblock %} of the theme file is ignored.
Right now I have to copy the whole theme file into my plugin to get the expected result
hey @ssltg, do you have any updates on this?
Hey @uehler , at first, sorry for the Delay. I tried to setup a similar system, but I cannot reproduce the behaviour you mentioned. I will contact you on Thursday morning. I guess I need to take a look at your actual setup.
We updated to shopware 6.1.3, but this is still not working. Looks like plugins and themes can only extend from templates with the same path. For example page/content/index.html.twig of a custom theme may only extend page/content/index.html.twig from the shopware theme but not from storefront/base.html.twig. In this case, any change a custom theme made to a custom storefront/base.html.twig is ignored and only the content of the base.html.twig of the shopware theme is loaded.
Not sure if it is the same problem but it sure sounds a lot like the one i'm having. @uehler Did you manage to solve it?
Right now i'm changing the inheritance order and placing my custom plugin after the theme in the theme.json file.
{
...
"views": [
"@Storefront",
"@Plugins",
"@CustomTheme",
"@CustomControllerPlugin"
],
...
}
But this is fundamentally flawed as i want plugins to be overriding the template. Or am i missing something else?
I didn't look further into it. Shopware did some patches which I have backported, which helped a bit, and I loaded the base.html.twig directly with my controller and only showed a flash message.
This is fixed with 6.4.0.0 with https://github.com/shopware/platform/pull/1396
Hi @ssltg,
I tried both,
clear:cacheandrm -rf /var/cache, both didn't help
I just wanted to mention that with this command rm -rf /var/cache you actually removed the cache folder in your linux directory /var. It is very dangerous to do that. You have to remove / from the beginning of the var. rm -rf var/cache/*