Twig block passed to embedded template

Viewed 970

I'm using twig templates in a slim framework app. I have a template page.phtml which paginates an array of data and has several sub blocks intended for overriding per element specifics like paginating users, events, orders, etc.

page.phtml

<div class="page">
    {% block block1 %}default content{% endblock %}
    <ul>
    ...
    </ul>
    {% block block2 %}{% endblock %}
</div>

I have an event.phtml template which embeds page.phtml and adds some other content to the page; it also overrides the default page's block1 content

event.phtml

<html>
    <body>
        <h1>Event Page</h1>
        {% embed "page.phtml" %}
            {% block block1 %}event page content{% endblock %}
        {% endembed %}
    </body>
</html>

I have a custom event page which needs only modify a few of the event page's blocks so I extended event.phtml like so

custom_event.phtml

{% extends "event.phtml" %}
{% block block2 %}overridden value{% endblock %}

and expected block2's overridden content to show up in the page.phtml template embedded by the parent template. I can output the value of block2 in the parent template and it's there, but in the embedded template it's not. I tried explicitly passing the block in event.phtml in the embed like so

{%embed "page.phtml" %}
    {% block block2 %}{{parent()}}{% endblock %}
    ...
{% endembed %}

But that yielded no difference. How do I get the overridden block2 from the custom_event.phtml template all the way through the extended event.phtml template and into the embedded page.phtml template?

1 Answers
Related