How can I find the path to an include in Symfony2?

varker picture varker · Jan 18, 2012 · Viewed 8.2k times · Source

I've looked thoroughly over Symfony related questions on this site but can't find the answer I need.

I'm using Symfony 2.0.9 with PHP 5.3.6 and my file structure looks like this:

src/
  Blog/
    TestBundle/
      Resources/
        views/
          Default/
            index.html.twig
            header.html.twig

Inside of index.html.twig I have:

<div id="header">
{% include "BlogTestBundle:Resources:Default:header.html.twig" %}
</div>

It keeps erroring out with

Twig_error_loader: Unable to find template

no matter what I use for the path. Why isn't it finding the file? They're even in the same directory!

Anyone have any idea what I'm doing wrong?

Answer

Inoryy picture Inoryy · Jan 18, 2012

twig file includes should follow the format below:

FullBundleName:ControllerName:filename

You can also amend parts if they're not present, i.e. for just a file under a bundle /views directory you can use FullBundleName::filename

So in your case, use BlogTestBundle:Default:header.html.twig