Sylius version affected: 1.2.3
Description
If you want to override a plugin's template (a plugin, not a bundle), and you want to use the theme for that, it's not working.
Steps to reproduce
Let's say you install the BitBagCms plugin.
Then you want to override the template @BitBagSyliusCmsPlugin/Shop/Page/show.html.twig.
And you want to do tat in your theme.
So you create this file:
app/themes/MyTheme/BitBagSyliusCmsPlugin/Shop/Page/show.html.twig
And according to everything it should work. But it doesn't.
Possible Solution
The bug is actually in https://github.com/Sylius/Sylius/blob/1.2/src/Sylius/Bundle/ThemeBundle/Templating/TemplateNameParser.php#L65-L75.
I did that to fix the problem (very succinct):
diff --git a/src/Sylius/Bundle/ThemeBundle/Templating/TemplateNameParser.php b/src/Sylius/Bundle/ThemeBundle/Templating/TemplateNameParser.php
index 0d7fbb1f5b..22191df875 100644
--- a/src/Sylius/Bundle/ThemeBundle/Templating/TemplateNameParser.php
+++ b/src/Sylius/Bundle/ThemeBundle/Templating/TemplateNameParser.php
@@ -66,8 +66,14 @@ final class TemplateNameParser implements TemplateNameParserInterface
return $this->decoratedParser->parse($name);
}
+ if (isset($matches[1]) && preg_match('/^.+Plugin$/', $matches[1])) {
+ $bundleName = $matches[1];
+ } else {
+ $bundleName = $matches[1] ? $matches[1] . 'Bundle' : '';
+ }
+
$template = new TemplateReference(
- $matches[1] ? $matches[1] . 'Bundle' : '',
+ $bundleName,
$matches[2],
$matches[3],
$matches[4],
It works well since we call the templates with the Plugin prefix:
@BitBagSyliusCmsPlugin/Shop/Page/show.html.twig
^^^^^^
Hello,
is this still true for version 1.3.3? I tried to overwrite templates for the CMS plugin as well, but failed. I wonder if I'm doing something wrong or if it's still this bug? Couldn't make it work with above fix either.
@chaenu sadly it is...
It used to work until 1.3.1
then after this commit only BUNDLES can be overriden in themes.
https://github.com/Sylius/Sylius/commit/e5a5042188b85b15f98b7ee8f9d3c1a4f9979a6b#diff-1703885a80095c3a851cfa73b366383d
After 1.3.1 neither of those declarations can be extended in theme folder:
{% include '@MyAmazingSyliusPlugin/Page/thisNeedsToBeOverridenInTheme.html.twig' %}
{% include 'MyAmazingSyliusPlugin::Page/thisNeedsToBeOverridenInTheme.html.twig' %}
Maybe @pamil has some insight why it was done this way.
Most helpful comment
@chaenu sadly it is...
It used to work until 1.3.1
then after this commit only BUNDLES can be overriden in themes.
https://github.com/Sylius/Sylius/commit/e5a5042188b85b15f98b7ee8f9d3c1a4f9979a6b#diff-1703885a80095c3a851cfa73b366383d
After 1.3.1 neither of those declarations can be extended in theme folder:
{% include '@MyAmazingSyliusPlugin/Page/thisNeedsToBeOverridenInTheme.html.twig' %} {% include 'MyAmazingSyliusPlugin::Page/thisNeedsToBeOverridenInTheme.html.twig' %}Maybe @pamil has some insight why it was done this way.