What we want to do is, passing assets to a base template block from a certain include level.
We have a setup similar like this:
A simple base template with a javascripts block...
- Code: Select all
#base.html.twig
{% block javascripts %}{% endblock %}
An index template which extends the base, where we want to include different boxes...
- Code: Select all
#index.html.twig
{% extends '::base.html.twig' %}
{% include 'MyBundle:Box:welcome.html.twig' %}
Welcome box...
- Code: Select all
#welcome.html.twig
{% block javascripts %}
<script type="text/javascript" src="/bundles/myotherbundle/js/welcome.js"></script>
{% endblock %}
At the level of the welcome box we want to add some welcome box specific javascript code.
It would be nice if the js code could be passed to the javascripts block defined in the base template. Unfortunately it seems that this is not possible with our approach.
Is our setup such an uncommon practice or is there a reason why this code does not work? Any hints/hacks/best practices on how to handle this problem would be appreciated!
