如何在其他模板的同一目录中扩展树枝模板? [英] How do I extend a twig template in the same directory of my other templates?

查看:32
本文介绍了如何在其他模板的同一目录中扩展树枝模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have index.html.twig and base.html.twig in the same directory folder..I have the following scipts

index.html.twig

index.html.twig

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

{% block body %}
    helo body
    {{ parent() }}
{% endblock %}
{% block footer %}
    This footer
{% endblock %}

base.html.twig

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>

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

It returns me with an error "Unable to find template "base.html.twig" in "FacebookBundle:Default:index.html.twig" .I also noticed some people have used :: just before the template name .. Why is that and how do I fix this ?

推荐答案

您必须在 index.html.twig<中扩展 FacebookBundle:Default:base.html.twig/代码>.

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

You use :: when you put your template directly in the view/ dir and not in a sub dir (i.e.: for layout in this example: Bundle::layout.html.twig instead of Bundle:Controller:index.html.twig)

Bundle
    Resources
        views
            Controller
                index.html.twig
            Default
                base.html.twig
                index.html.twig
            layout.html.twig

这篇关于如何在其他模板的同一目录中扩展树枝模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆