Gasim
Gasim

Reputation: 7991

Symfony2 cannot render template inside Bundle

I have the following structure:

/src/Product/AdminBundle/Resources/views/main.twig

I am trying to render this template from controller:

$this->render(...);

or from routing.yml

index_page:
    path: /
    defaults:
         _controller: FrameworkBundle:Template:template
         template: ...

How can I render this from from inside the controller in the bundle? Here is what I have tried with no luck:

Upvotes: 1

Views: 4437

Answers (4)

Steve Build
Steve Build

Reputation: 3

AdminBundle::main.twig does not work

rename main.twig into main.html.twig

After that AdminBundle::main.html.twig will work!

Upvotes: 0

Alain
Alain

Reputation: 36984

The usual path syntax is:

BundleName:DirectoryInView:file.html.twig

In your case, this will be:

ProductAdminBundle::main.html.twig

We use ::, because your view is located in the root directory.

Upvotes: 5

Gasim
Gasim

Reputation: 7991

After trying every possible combination this is the one that worked for me:

@AdminBundle/Resources/views/main.twig

Upvotes: 1

scoolnico
scoolnico

Reputation: 3125

Try like this:

return $this->render('ProductAdminBundle:main.html.twig', []);

Where main.html.twig is your view name (and not main.twig).

Upvotes: 0

Related Questions