5
votes

I have a child template which extends ::base.html.twig. The base template includes a javascripts block. I can override the included javascripts inside my child template.

But then if I do an twig include to a third template which just contains a form, I cannot inject additional javascript from the third template inside the child template inside the javascripts block (or a nested block)

There is further detail here - https://gist.github.com/3182772

Is this possible?

This github issue seems to suggest that it isn't but traits are no good to me as I am extending a base template.

https://github.com/fabpot/Twig/issues/644

1

1 Answers

5
votes

You don't need the inner block. Just keep doing this:

{% block javascripts %}
    {{ parent() }}

    {# put additional JS here #}
{% endblock %}

You can keep doing this for as much levels as you need.