Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I extend a twig template in the same directory of my other templates?

Tags:

twig

symfony

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

index.html.twig

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

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

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>

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 ?

like image 265
Manish Basdeo Avatar asked Dec 09 '22 22:12

Manish Basdeo


1 Answers

You'll have to extend FacebookBundle:Default:base.html.twig in your 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
like image 155
guillaumepotier Avatar answered Dec 11 '22 10:12

guillaumepotier