如何在我的其他模板的同一目录中扩展树枝模板?

Vim*_*deo 4 symfony twig

我有index.html.twig和base.html.twig在同一个目录文件夹中..我有以下scipts

index.html.twig

{% extends('base.html.twig') %}

{% block body %}
    helo body
    {{ parent() }}
{% endblock %}
{% block footer %}
    This footer
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

base.html.twig

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>{% block title %}Welcome!{% endblock %}</title>
        {% block stylesheets %}{% endblock %}
        <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
    </head>
    <body>
        {% block body %}The body block{% endblock %}
        {% block sidebar %}The body sidebar{% endblock %}

    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

它返回一个错误"无法找到模板"base.html.twig"in"FacebookBundle:Default:index.html.twig".我也注意到有些人在模板名称前面使用过::为什么会这样我该如何解决这个问题?

gui*_*ier 14

你必须扩展FacebookBundle:Default:base.html.twig你的index.html.twig.

::将模板直接放在view/目录中而不是在子目录中时使用(即:对于此示例中的布局:Bundle::layout.html.twig代替Bundle:Controller:index.html.twig)

Bundle
    Resources
        views
            Controller
                index.html.twig
            Default
                base.html.twig
                index.html.twig
            layout.html.twig
Run Code Online (Sandbox Code Playgroud)