Reputation: 4936
A little issue that has been bugging me; with PHP & twig
I need to include javascripts in a certain order
This is my layout flow
app_layout.twig - this is my core app layout with headers and footers, with its own js as well
module.twig - I extend app_layout.twig here. Module has its own set of javascript files
sub-module.twig - This is included inside module and has its own js.
How can include javascript inside sub-module that will add at the end of the page?
Example module.twig
{% extends "app_layout.twig" %}
<-- some html -->
{% include "submodule.twig" %}
{%block js_includes%}
<-- some js includes here -->
{%endblock%}
{%block sub_js_includes%}
{%endblock%}
Example submodule.twig
<-- some html -->
{%block sub_js_includes %}
<-- js for submodule
{%endblock%}
But the sub_js_includes are included even before js_includes. How can i make sure the subjs includes are indeed after the module js includes?
Thanks
Upvotes: 2
Views: 84
Reputation: 9113
This is not possible. A include does exactly that, including. I think you are looking for parent function. Then you can restructure your coode to extend more then once.
Example module.twig
{% extends "app_layout.twig" %}
{%block js_includes %}
<-- some js includes here -->
{%endblock%}
{%endblock%}
Example submodule.twig
{% extends "module.twig" %}
{%block js_includes %}
{{ parent() }}
<-- more js includes here -->
{%endblock%}
{%endblock%}
Upvotes: 1