Access to js and css in after upgrade to symfony 3.4

402 Views Asked by At

I upgraded my symfony project from 2.8 to 3.4. All is OK except access to js and css.

As I used assetic bundle in 2.8, I kept it after upgrade. When I try to update js/css in my project, I run the commands php bin/console cache:clear , php bin/console assets:install web and php bin/console assetic:dump. The problem is that js/css are stored in web/bundles/mybundle/.. but they are called in web/css et web/js in HTML. This issue is the same for dev or prod environment.

This is an exemple of the code in my twig template :

{% javascripts  '@MyBundle/Resources/public/js/add_detail.js'
'@MyBundle/Resources/public/js/add_publication.js                   %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

In the final HTML, the js is called with this line :

<script type="text/javascript" src="/js/db6ab9c_add_detail_1.js"></script>
<script type="text/javascript" src="/js/db6ab9c_add_publication_2.js"></script>

How can I make to have a good reference for my css/js in HTML code ?

2

There are 2 best solutions below

3
Heyden7611 On

Test =>

php bin/console cache:clear

php bin/console assets:install  (without web)

php bin/console assetic:dump

Or You can call your file one by one with {{ asset('') }}

0
Lucuhb On

I found the problem : it was due to the fact that I put my templates in a /templates directory on root of my project. When I put templates in app/Resources/views directory, assets are correctly created in web/js and web/css with the php bin/console assetic:dump command. Assets referenced in html are so properly loaded.