Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I inject javascript blocks from a child template in Symfony2?

Tags:

twig

symfony

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

like image 813
codecowboy Avatar asked Jul 26 '12 16:07

codecowboy


1 Answers

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.

like image 58
Elnur Abdurrakhimov Avatar answered Oct 17 '22 02:10

Elnur Abdurrakhimov