berimbolo
berimbolo

Reputation: 3829

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?

Upvotes: 3

Views: 1948

Answers (2)

Doc Roms
Doc Roms

Reputation: 3308

404 Error will be trough when the file don't exist on your server!(not found...) (W3 official doc here). The file don't exist in your target folder (or you target the wrong file ^^) ...

have you think to load your ressources in your web/ folder with this command:

# make a hard copy of the assets in web/
$ php app/console assets:install

# if possible, make absolute symlinks in web/ if not, make a hard copy
$ php app/console assets:install --symlink

# if possible, make relative symlinks in web/ if not, make a hard copy
$ php app/console assets:install --symlink --relative

This a new command on SF2.6 and you can find more samples of this command documentation here

you have all the documentation of assetics on the officoal symfony website. And few idea for the best practise here.

Also, it's better to use the ' character in your asset() function like that :

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

Upvotes: 3

vardius
vardius

Reputation: 6546

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.

Upvotes: 3

Related Questions