0
votes

I am using Symfony and Twig and the fragment sub-framework more specifically the Internal sub-requests.

In any case when I request a template using a fragment include

 {% render url('route_name') %}

and my fragment code looks like this for example

 <div>[code here...]</div>
 <script>[javascript here...]</script>

how can I get this javascript to load into a {% block %} in my base.html.twig file? If I extend my fragment and put {% extends '::base.html.twig' %} in the header it will include the entire layout of my site. I just want to be able to push the javascript from from fragment out to my base template.

In my base template I have a {% block %} such as this

 {% block javascript_footer %}
      [it inherits javascript from child templates...]
 {% endblock %}

Thanks!

1

1 Answers

0
votes

separate your javascript into another file and than include it into your base template and also into your fragment.

base template:

{% block javascript_footer %}
    {% include '::javascript.html.twig' %}
{% endblock %}

your fragment:

<script>{% include '::javascript.html.twig' %}</script>

assuming that javascript.html.twig doesnt include <script> tag already