Laurent Voiry
Laurent Voiry

Reputation: 49

Symfony2:css, images and assetic

I've put a css file in MyDirectoryBundle/Resources/public/css. I then linked to it using:

<link href="{{ asset('css/main.css') }}" type="text/css" rel="stylesheet" />

I checked if it worked

short test: body {color: #FF0000;}

Nothing changed.

The parent layout (layout.twig.html) is in app/Resources/views (3 level architecture).

I still don't understand why:

I am quite new to symfony2 (2 weeks practice only). I am working on Windows - just in case this may explain something...

Thank you very much for your help!

Upvotes: 0

Views: 118

Answers (2)

Abdelaziz Dabebi
Abdelaziz Dabebi

Reputation: 1638

use php app/console instead of php console

Upvotes: 1

Wouter J
Wouter J

Reputation: 41934

  1. If the file first lived in MyDirectoryBundle/Resources/public/css, it'll be copied to web/bundles/mydirectory/css. So you have to include it like: {{ asset('bundles/mydirectory/css/main.css') }}.
  2. You should execute the command from the root of your project. As you're using php console, it seems like you're in the app/ directory when executing this command. In that case, app/web/ does not exists, so the error is completely valid.
  3. As you're on Windows, there is a change that symlink is not allowed/available. I believe it's available for admins only since Windows vista.

As a side tip, if MyDirectoryBundle is your app bundle (a bundle tied to your app and not meant to be reused by other apps), I would recommend to put the CSS file in the web/ directory directly. There is no need to put it in the bundle in such a case (this is only related to bundles that are shared, so the CSS is shared as well).

Upvotes: 1

Related Questions