Sylius / SyliusThemeBundle

Theming for Symfony, supports templates, assets and translations.
https://sylius.com
MIT License
93 stars 34 forks source link

Application template not looked for in theme directory #72

Open armellarcier opened 3 years ago

armellarcier commented 3 years ago

I have a route mapped to a template name

shop_domaines_show:
    path: /domaines/{slug}
    defaults:
        _controller: black_sylius_marketplace.controller.seller:showAction
        _sylius:
            template: 'Shop/views/domaines/show.html.twig'
            repository:
                method: findOneBySlug
                arguments:
                    - $slug

And a template in templates/Shop/views/domaines/show.html.twig

It works ok.

When I want to override this template in the theme it fails.

I put a new file in themes/MyTheme/Shop/views/domaines/show.html.twig

And it's not loaded.

If I remove the template in the templates dir, leaving only the one in the theme, here is the error I get :

Unable to find template "Shop/views/domaines/show.html.twig" (looked into: /project/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views, /project/templates, /project/templates, /project/vendor/symfony/twig-bridge/Resources/views/Form).

The loader is not looking in the theme directory. Note it seems to be looking twice in the /project/templates dir.

The problem only occurs for app templates.

Bundle templates are loaded fine from the theme directory. (/theme/MyTheme/SyliusShopBundle/views/Homepage/index.html.twig works perfetcly)

The theme is enabled of course

I'm using Sylius 1.8 and sylius/theme-bundle 1.5.1

armellarcier commented 3 years ago

A temporary fix is to add the theme directory to twig paths but it is not a solution

in config/packages/twig.yaml

twig:
    # DO NOT COMMIT THIS!
    paths: ['%kernel.project_dir%/themes/MyTheme', '%kernel.project_dir%/templates']