Modify Twig block inside another block

Viewed 6026

layout.twig

<main class="main">
    {% block content %}{% endblock content %}
</main>

{% block footer %}{% endblock %}

page.twig

{% extends 'layout.twig' %}
{% block content %}
{#abc#}
    {% block footer %}
        {#123#}
    {% endblock footer %}
{% endblock content %}

When I do this. Footer block renders twice. Once after content block and once the place it should be

NOTE: I simplifed the templates to make them more readable. The problem I see is I cannot use block inside another block. if I use it renders twice.

I have to use footer inside block content. I don't want to include extends and content in every page. Because it is same. I use something like below.

        $tm['p'] = "{% extends '" . $layout . "' %}{% block content %}";
        $tm['p'] .= $page;
        $tm['p'] .= "{% endblock content %}";

        $load = new \Twig_Loader_Array($tm);
        $tw = new \Twig_Environment($load);
        print $tw->render("p", $dat);
1 Answers
Related