无法找到模板" layout.html.twig" Symfony3

时间:2016-12-11 19:03:40

标签: html templates include twig symfony

我有这个代码并且它给了我错误: 无法找到模板" layout.html.twig"在第1行的Categorias \ listar.html.twig中。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>{% block title %}LAYOUT title - CATEGORIAS{% endblock %}</title>
        <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
        {% block stylesheets %}
            <style>
                .container{
                    border: 1px solid black;
                    background: #eee;
                    width: 85%;
                    height: 300px;                    
                }
            </style>
        {% endblock %}

    </head>
    <body>
        <div class="container">
            {%block container %}
                Contenido por defecto de CATEGORIAS LAYOUT
            {%endblock %}
        </div>
        {% block body %}<h1>HOLA SOY EL bloque Body por defecto de CATEGORIAS</h1>{% endblock %}
        {% block javascripts %}{% endblock %}
    </body>
</html>
{% extends "layout.html.twig" %}
{%block container %}

    <h1>Contenido del body customizado en listar.html.twig</h1>
{%endblock%}

Folders link

3 个答案:

答案 0 :(得分:1)

路线必须是:

&#13;
&#13;
{% extends "Categorias/layout.html.twig" %}
{% block title %}Estas en la vista de categorias{% endblock %}

{% block body %}
    
    Esto es el body de listar categorias
    
{% endblock %}
&#13;
&#13;
&#13;

答案 1 :(得分:0)

尝试:

{% extends '::Categorias/layout.html.twig' %}

而不是:

{% extends "layout.html.twig" %}

希望这个帮助

答案 2 :(得分:0)

应该是这样的:

{% extends "app:categorias:layout.html.twig" %}

{%block container %}
    <h1>Contenido del body customizado en listar.html.twig</h1>
{%endblock%}

此外,如果您绑定app,则应将其称为AppBundle。 (如果您的项目进展顺利,则需要进行大量编辑) 我还建议将categorias重命名为Categorias(尽管是个人品味)

最后,但并非最不重要的是,如果您计划将您的布局用于categorias文件夹之外的twig文件,我建议您创建一个Comun文件夹,在其中放置小树枝由其他文件使用,然后将您的代码更改为:

{% extends "app:comun:layout.html.twig" %}

{%block container %}
    <h1>Contenido del body customizado en listar.html.twig</h1>
{%endblock%}

如果您应用所有建议,它将变为:

{% extends "AppBundle:Comun:layout.html.twig" %}

{%block container %}
    <h1>Contenido del body customizado en listar.html.twig</h1>
{%endblock%}
相关问题