Reputation: 165
I am using jQuery in my Symfony2 application and I have a "ReferenceError: jQuery is not defined" error. I think changing Javascript file load order could fix this.
How could I force to load jQuery Javascript file first in order to avoid such errors? I would like to keep the "js/*" in order to load auto-magically the future new JS files I will put.
Here is stylesheets part of my *.html.twig template:
{% javascripts
'@xxxBundle/Resources/public/js/*'
'js/*'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
And here is current output generated by Symfony2:
<script type="text/javascript" src="/Symfony/web/app_dev.php/js/8d3a8ee_part_2_acidTabs_1.js"></script>
<script type="text/javascript" src="/Symfony/web/app_dev.php/js/8d3a8ee_part_2_jquery-1.6.min_2.js"></script>
Upvotes: 3
Views: 2144
Reputation: 10356
You can list your core dependencies first, then load all others:
{% javascripts
'@xxxBundle/Resources/public/js/*'
'js/example_1.js'
'js/example_2.js'
...
'js/*' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
Upvotes: 7