Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including the twig file from a subdirectory

Tags:

twig

symfony

I've got a problem - I can't include a twig file in another twig file when it's placed in the subdirectory. Example:

I've got a file AppUserBundle:Dashboard:index.html.twig (symfony path is src/App/UserBundle/Resorcues/views/Dashboard/index.html.twig and so are the other views' paths). In that file I've got include for a file Status.html.twig placed in AppUserBundle:Dashboard:User subdirectory. But when trying to include it I'm getting message 'can't find template'.

{% include 'AppUserBundle:Dashboard:User:Status.html.twig' %}

When I move the Status.html.twig file to AppUserBundle:Dashboard directory and include it everything works just fine. Can I somehow get to any file like that?

AppUserBundle:Dashboard:Subdir:file
like image 257
thorinkor Avatar asked Nov 22 '12 14:11

thorinkor


1 Answers

AcmeDemoBundle:Welcome is just a logical controller name, the : doesn't mean a /. This logical name refers to the @AcmeDemoBundle/Resources/views/Welcome directory where @AcmeDemoBundle is a logical bundle name which become something like src/Acme/DemoBundle.

If you want to add another directory to the name, just place it after the logical name as you normally do:

AcmeDemoBundle:Welcome:User/index.html.twig

This refers to the src/Acme/DemoBundle/Resources/views/Welcome/User/index.html.twig file.

like image 104
Wouter J Avatar answered Nov 08 '22 06:11

Wouter J