Description
Hello,
I've come across a limitation of the Twig Component where I can't access multiple level outerBlocks.
Considering this case :
{# templates/activity/_base_activity.html.twig #}
{% block tabs %}
<twig:Ui:Tabs:Trigger value="content">
{{ outerScope.content_tab_label|default('label.activity.content'|trans) }}
</twig:Ui:Tabs:Trigger>
{% if show_resources|default(false) %}
<twig:Ui:Tabs:Trigger value="resources">
{{ 'label.activity.resources'|trans }}
</twig:Ui:Tabs:Trigger>
{% endif %}
{% block additional_tabs %}{% endblock %}
{% endblock %}
{% block content_panel %}{% endblock %}
{% block additional_panels %}{% endblock %}
<twig:Ui:Tabs:Root>
<twig:Ui:Tabs:List>
{{ block(outerBlocks.tabs) }}
</twig:Ui:Tabs:List>
{% block panels %}
<twig:Ui:Tabs:Panel value="content" aria-hidden="false">
{{ block(outerBlocks.content_panel) }}
</twig:Ui:Tabs:Panel>
{% if show_resources|default(true) %}
<twig:Ui:Tabs:Panel value="resources">
{{ include('activity/_attachment_list.html.twig', {'attachments': attachments}, with_context: false) }}
</twig:Ui:Tabs:Panel>
{% endif %}
{% endblock %}
</twig:Ui:Tabs:Root>
{# templates/activity/_fallback.html.twig #}
{% extends 'activity/_base_layout.html.twig' %}
{% block content_panel %}
{{ dump(activity) }}
{% endblock %}
The last template was supposed to override the content_panel, but after rendering, both the <twig:Ui:Tabs:List>
and the content tab panel are empty.
I tried using outerBlocks.outerBlocks
and outerScope.outerBlocks
from the <twig:Ui:Tabs:List>
component content but they all return the fallback block name.
I managed to make the previous code by using the following workaround, but it souns hackish and may become hard to maintain if I had to access blocks deeper in the component tree :
{# templates/activity/_base_activity.html.twig #}
{% block tabs %}
<twig:Ui:Tabs:Trigger value="content">
{{ outerScope.content_tab_label|default('label.activity.content'|trans) }}
</twig:Ui:Tabs:Trigger>
{% if show_resources|default(false) %}
<twig:Ui:Tabs:Trigger value="resources">
{{ 'label.activity.resources'|trans }}
</twig:Ui:Tabs:Trigger>
{% endif %}
{% block additional_tabs %}{% endblock %}
{% endblock %}
{% block content_panel %}{% endblock %}
{% block additional_panels %}{% endblock %}
<twig:Ui:Tabs:Root>
{% block tabs %}
{{ block(outerBlocks.tabs) }}
{% endblock %}
{# Same hack for other top level blocks #}
<twig:Ui:Tabs:List>
{{ block(outerBlocks.tabs) }}
</twig:Ui:Tabs:List>
{% block panels %}
<twig:Ui:Tabs:Panel value="content" aria-hidden="false">
{{ block(outerBlocks.content_panel) }}
</twig:Ui:Tabs:Panel>
{% if show_resources|default(true) %}
<twig:Ui:Tabs:Panel value="resources">
{{ include('activity/_attachment_list.html.twig', {'attachments': attachments}, with_context: false) }}
</twig:Ui:Tabs:Panel>
{% endif %}
{% endblock %}
</twig:Ui:Tabs:Root>
I'd like if I'm doing something wrong. What would be the best way to achieve what I'm looking for ? And what would be alternatives if I had to come back to an approach without components ?