Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find template Symfony2

I would like to include a template in my view but it doesn't work, I have this error :

Unable to find template "::StyleBlock/light-pattern.html.twig" in ::base.html.twig at line 46.

My code :

{% for zone in content.blocks %}
    {% set path = '::StyleBlock/' ~ zone.styles %}
    {% include path %}
{% endfor %}

In the details i have this message :

InvalidArgumentException: The file "views/StyleBlock/light-pattern.html.twig" does not exist (in: /var/www/gathena/app/Resources).

But the path is correct, i don't understand.

I use Symfony 2.3 and I have the good permission on my directory

like image 931
Kev Avatar asked Mar 22 '23 22:03

Kev


1 Answers

You have given wrong path, it should be:

{% for zone in content.blocks %}
    {% set path = 'CmsCmsBundle:StyleBlock:' ~ zone.styles %}
    {% include path %}
{% endfor %}

as for path src/Cms/CmsBundle/Resources/views/StyleBlock/

The first parameter is your bundle, second is the controller in this case StyleBlock, so your views are in your bundle in Resources/views/StyleBlock directory, last parameter is the template name which is defined by your loop variable in this case. It should only be your template name, without any absolute paths. All parameters are seperated by :

like image 183
Wilq Avatar answered Apr 02 '23 18:04

Wilq