Veeru
Veeru

Reputation: 4936

Twig: Javascript inclusion order

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

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

Answers (1)

oshell
oshell

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

Related Questions