Search code examples
symfonypathcontrollersassetic

Symfony 2 assetic wrong path with use_controllers: false


I tried to set use_controllers to false in debug mode, because on my machine, it takes 5 to 15 seconds, then I Generated the assets manually.

The generated files are fine, but when I open a page in my browser, no css or js files gets loaded. I took a look in the developer tools, and saw, that symfony is trying to load the files from "localhost/_controller/js/08f6dbe_jquery-1.7.2.min_1.js". If I remove the "_controller" in the path manually it works fine, but I have no idea, why symfony generate the wrong path.

Some code:

#config_dev.yml

assetic:
use_controller: false

base.html.twig

{% javascripts '../app/Resources/public/js/libs/jquery-1.7.2.min.js'
     <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %} 

I hope your can help me, and sorry for bad english


Solution

  • You can set output="js/*.js" in your twig tpl

    {% javascripts 
        '../app/Resources/public/js/libs/jquery-1.7.2.min.js' output='js/*.js'
         <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %} 
    

    This should generate something like this - "//localhost/js/f31e898_jquery_.js"
    you can replace the * with an actual name 'jquery' for example but to avoid caching it's beter to use the *.

    hope this helps