Search code examples
symfonyassetsdevelopment-environment

Symfony - Assets in dev mode


I am working through symfony tutorials and the documentation, it seems to imply that in dev mode the resources are available without having to install the assets, something like:

<link rel="stylesheet" href="{{ asset("bundles/yodauser/css/login.css") }}" />

I get a 404 error though in dev mode until I actually run the assets:install command.

What am I doing wrong?


Solution

  • Quoting documentation:

    http://symfony.com/doc/current/book/templating.html#including-stylesheets-and-javascripts-in-twig

    You can also include assets located in your bundles' Resources/public folder. You will need to run the php bin/console assets:install target [--symlink] command, which moves (or symlinks) files into the correct location. (target is by default "web").

    <link href="{{ asset('bundles/acmedemo/css/contact.css') }}" rel="stylesheet" />
    

    It should work, in my case sometimes it does sometimes it doeasnt. Worst case scenario you will have to run command every time you update assets.