0

I'm trying to link the stylesheet to an html template, but it doesn't seem to work.

I use symfony2 and assetic. In the demo bundle, the css is linked with the line:

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

So, in my mainBundle, I wrote the lines

<head>
<style>  
  {% block stylesheets %}
    <link href="{{ asset('bundles/acmemain/css/demo.css') }}" rel="stylesheet" />      
  {% endblock %}                               
</style>      
</head>

and put my demo.css file in the folder

Acme\MainBundle\Resources\public\css,

then I executed

 php app/console assets:install

In this situation, my web page doesn't have css style, it is without formattation. If I write my css directly in my template, it works. But if I link it, it doesn't work.

How can I solve this?

My css file now is only a line:

h1{color:blue;text-align:center;}

Thank you.

  • 1
    Possible duplicate > http://stackoverflow.com/questions/12165485/how-to-include-css-file-in-symfony-2-and-twig – Ahmed Siouani Mar 24 '14 at 12:05
  • Did you run `php app/console asset:install`? – Javad Mar 24 '14 at 14:03
  • Is your template extended from something? Do you have parent `block stylesheet`? – Javad Mar 24 '14 at 21:04
  • @Javad Yes, it is extended. But no template extends the block stylesheets. And if I put code in this block, it works, so it is not overwritten. I tried also to put it out of the {% block stylesheets %}, so there is not extension problem. – user3455230 Mar 24 '14 at 21:38
  • OK I suggest to get view source of the page and check the path for the stylesheet; then copy that URL and paste in a separate browser and try to download it, if did not work try to change it manually to find what's exact correct address then apply it to the your code – Javad Mar 24 '14 at 23:43

1 Answers1

1

You have to execute this command to copy your stylesheets (found in the public folder) in your web folder because asset() function looking sheets in this folder

  php app/console asset:install

Look at the doc for more explanations

Goku
  • 2,157
  • 2
  • 16
  • 31