is there any way to call parent() function in extending block in the template of the custom extension?
In my base.html.twig I have block footer_javascript
and in my custom extension I would like to add some JS to this block but I need to ensure that original block footer_javascript
will be extended not overwritten. I tried this:
custom_extension.html.twig:
{# some html/twig code, not really important #}
{% block footer_javascript %}
{{ parent() }}
{# some javascript for this custom twig extension #}
{% endblock footer_javascript %}
but of course, I get
Calling "parent" on a template that does not extend nor "use" another template is forbidden
base.html.twig - base template with block structure:
{# base html/twig structure, not really important %}
{# block which will be extended/overwriten in templates which extends this base.html.twig #}
{% block footer_javascript %}
{% endblock footer_javascript %}
extended.html.twig - template which extends base.html.twig; in this template I am using custom twig extension:
{% extends "::base.html.twig" %}
{# some html/twig ... #}
{{ custom_extension(entity) }}
{% block footer_javascript %}
{{ parent() }}
{# javascript used for extend.html.twig #}
{% endblock footer_javascript %}
Is there any way to extend base footer_javascript
in my custom extension template?
base.html.twig
? – Bartek