Skip to content

Overriding block in included/embedded files #1360

Description

@jpass

Including template should give the parent template ability to override blocks. Here comes the embedd tag. But when parent template is further included/embedded we have no ability to override those block anymore.

My problem:

{# _index_row.html.twig #}
<tr>
    <td>{% block actions %}{% endblock %}</td>
<tr>
{# _index.html.twig#}
<table>
    {% for entity in entities %}
        {% include _index_row | default('_index_row.html.twig') %}
    {% endfor %}
</table>
{# index.html.twig #}
{% extends layout | default( 'some_layout.html.twig') %}

{% block content %}
    <div>
        {% include _index | default('_index.html.twig') %}
        {% block foobar %}{% endblock %}
    </div>
{% endblock %}

Those templates come in reusable bundle, and they are cut to pieces so i can use table or table row to present data in another context or by using ajax.

When i need to override some parts of this structure i can simply use:

{# new_index.html.twig #}
{# here i can override included files like set _include 'overriding file' #}
{% extends 'index.html.twig' %}

{# here i can override block of parent template but not its included children #}
{% block actions %}
    add some content
{% endblock %}

The file "new_index.html.twig" doesn't have any ability to override blocks of included and/or embedded files down the template tree.

Shouldn't include tag work as 'copy and paste' for part of code? Or maybe embedd tag should open the block for overriding?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions