New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load vendor templates #652

Closed
garak opened this Issue Sep 20, 2017 · 8 comments

Comments

Projects
None yet
5 participants
@garak
Contributor

garak commented Sep 20, 2017

I'm stuck with loading vendor templates, that was automagically done in "old" Symfony apps.
For example, the menu from KnpMenu (KnpMenuBundle::menu.html.twig) is not loaded.

Steps to reproduce:

  • install this app
  • composer require knplabs/knp-menu-bundle
  • create a menu as a service, as described in bundle docs (example provided below)
  • call menu from a template

Expected: the menu should show
Actual: exception Unable to find template "KnpMenuBundle::menu.html.twig" (looked into: /home/user/symfony-demo/templates, /home/user/symfony-demo/vendor/symfony/twig-bridge/Resources/views/Form).

Note: for now I added the path of vendor template in twig.yaml and of course if works, but I think this is just an ugly workaround and I expect that any vendor template should work out of the box


Menu class example, provided to easy reproduction:

<?php
// src/Menu/Builder.php
namespace App\Menu;

use Knp\Menu\FactoryInterface;

class Builder
{
    private $factory;

    public function __construct(FactoryInterface $factory)
    {
        $this->factory = $factory;
    }

    public function createMainMenu(array $options)
    {
        $menu = $this->factory->createItem('root');
        $menu->addChild('Home', array('route' => 'homepage'));

        return $menu;
    }
}

added in config/services.yaml

    app.menu_builder:
        class: App\Menu\Builder
        arguments: ["@knp_menu.factory"]
        public: true
        tags:
            - { name: knp_menu.menu_builder, method: createMainMenu, alias: main }

added in templates/default/homepage.html.twig (inside body block)

{{ knp_menu_render('main') }}
@garak

This comment has been minimized.

Contributor

garak commented Sep 20, 2017

Other example, easy to reproduce: try to use KnpPaginatorBundle with provided bootstrap3 template, getting Unable to find template "KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig"

@stof

This comment has been minimized.

Member

stof commented Sep 20, 2017

When the templating component is not installed and enabled, you cannot use the Bundle:Folder:file.html.twig notation for template name.

you would have to use the native Twig syntax (which is enabled in Symfony since 2.6 IIRC, but definitely a long time): @KnpPaginator/Pagination/twitter_bootstrap_v3_pagination.html.twig

@garak

This comment has been minimized.

Contributor

garak commented Sep 20, 2017

So, I required symfony/templating, what do I need more?
Maybe this should be covered at least in docs, to make easier a transition from old applications

@yceruto

This comment has been minimized.

Contributor

yceruto commented Sep 20, 2017

IMHO is the bundle who should change the notation to use Twig syntax by default or require it.

@javiereguiluz

This comment has been minimized.

Member

javiereguiluz commented Sep 20, 2017

I agree with @yceruto. This looks like it should be solved in the third-party bundle:

  • Sort term solution: they must add symfony/templating as a dependency if they use the bundle notation.
  • Long term solution: they should never use the bundle notation and transition to namespaced templates.

So, let's close this as "won't fix" and continue the discussion in KnpLabs/KnpMenuBundle#355.

@garak

This comment has been minimized.

Contributor

garak commented Sep 20, 2017

Right, but I'm missing something: even if I required templating, I'm stuck with the exception

@javiereguiluz javiereguiluz reopened this Sep 20, 2017

@rosier

This comment has been minimized.

Contributor

rosier commented Sep 20, 2017

You also need to enable the templating component in your config:

framework:
    templating:
        engines: ['twig']
@garak

This comment has been minimized.

Contributor

garak commented Sep 20, 2017

It's working, using @rosier suggestion. Thank you everyone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment