【问题标题】:Unable to find template "layout.html.twig" Symfony3找不到模板“layout.html.twig”Symfony3
【发布时间】:2016-12-11 19:03:40
【问题描述】:

我有这段代码,它给了我错误:无法在第 1 行的 Categorias\listar.html.twig 中找到模板“layout.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

【问题讨论】:

    标签: html templates include twig symfony


    【解决方案1】:

    路线必须是:

    {% extends "Categorias/layout.html.twig" %}
    {% block title %}Estas en la vista de categorias{% endblock %}
    
    {% block body %}
        
        Esto es el body de listar categorias
        
    {% endblock %}

    【讨论】:

      【解决方案2】:

      尝试:

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

      代替:

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

      希望有帮助

      【讨论】:

        【解决方案3】:

        应该是这样的:

        {% extends "app:categorias:layout.html.twig" %}
        
        {%block container %}
            <h1>Contenido del body customizado en listar.html.twig</h1>
        {%endblock%}
        

        另外,如果 app 是你的捆绑包,那么它应该被称为 AppBundle。 (如果您的项目非常先进,则需要进行大量编辑)
        我还建议将categorias 重命名为Categorias(不过个人口味)

        最后但并非最不重要的一点是,如果您打算将布局用于 categorias 文件夹之外的树枝文件,我建议创建一个 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%}
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-01-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-12-27
          • 2016-07-22
          • 2017-01-08
          • 1970-01-01
          相关资源
          最近更新 更多