I am trying to override a {% block %} in a file (index.html.twig) that extends the file where the block is used (base.html.twig). But the extending file is including another twig file (feature.twig) where the block that overrides the content in index.html.twig is placed. Is that possible in any way? Maybe with something else than the include statement?
{# index.html.twig #}
{% extends 'base.html.twig' %}
{{ include('feature.html.twig') }}
{# base.html.twig #}
{% block extraJs %}{% endblock %}
{# feature.html.twig #}
{% block extraJs %}<script>$('...');</script>{% endblock %}
include
returns the rendered version, so I don't think you can do anything with this setup. – Yoshiembed
twig.sensiolabs.org/doc/tags/embed.html but I don't think it resolve your problem, sorry. – ofcaindex
extendsbase
, why not do it the easy way and (inindex
) declare:{% block extraJs %}{{ include('feature.html.twig') }}{% endblock %}
. And infeature
just render the content, no blocks. – Yoshi