0

binding a CSS-File should be simple in symfony 3 according to every tutorial and the documentation. But in my case, it just doesn't work.

In my base.html.twig i have

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

while in the folder web/assets/css/ there is a main.css file. But it just doesn't take effect.

Did I do something wrong?

EDIT:

maybe one more info.. when i look at the sourcecode there is a <link rel="stylesheet" href="/assets/css/main.css" /> in the head of the document, but when I click on the link it outputs a No route found for "GET /assets/css/main.css" (from "http://localhost/application/3")

EDIT 2:

maybe this might help.. the log-file says

2016-06-24 18:30:32] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /css/main.css" (from "http://localhost/")" at D:\xamp\htdocs\icp\var\cache\dev\classes.php line 2357 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET /css/main.css\" (from \"http://localhost/\") at D:\\xamp\\htdocs\\icp\\var\\cache\\dev\\classes.php:2357, Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0):  at D:\\xamp\\htdocs\\icp\\var\\cache\\dev\\appDevUrlMatcher.php:166)"} []
10
  • What do you mean with "doesn't take effect"? What is the resulting HTML? Commented Jun 22, 2016 at 17:40
  • I mean that in the head of the html there is a <link rel="stylesheet" href="/assets/css/main.css" /> outputed where a css-selector defined and in the body there is a div with this class, but the css doesn't take effect .. just like if it would not be there Commented Jun 22, 2016 at 20:01
  • So, the asset helper is working and you're asking for a CSS help? You failed your topic, indeed Commented Jun 23, 2016 at 7:54
  • @MassimilianoArione ..I'm not sure if the asset-helper is working :/ ..as I mentioned.. the Path is in the HEAD of the site.. the CSS-file definetly exists.. but it is not accessible from the browser Commented Jun 23, 2016 at 9:29
  • The only task the asset helper must execute is transforming a relative URL into an absolute URL, and that is working, since you can see the correct path in the HTML source. Not getting that file by calling it directly is a different thing. By the way, accessing to static files (like CSSs) is not passing by Symfony at all, it's handled directly by web server (as long as the static file exists, of course) Commented Jun 23, 2016 at 12:07

2 Answers 2

1

The main problem will be of course your implementation of your {{ assets }}

If you follow the documentation of symfon, your code should look like

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

instead of

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

Anyways today I solved one problem with symfony and css and the solution may affect your problem:

If your are working with Chrome, try to disable your cache. (To do that, Ctrl+Shift+i, network, the checkboxes on the head).

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you forgotten to extends base.html.twig from your bundle, but with informations you give to us it should work.

3 Comments

I do a {% extends 'base.html.twig' %} in the template file.. in the head of the HTML there is a <link rel="stylesheet" href="/assets/css/main.css" /> but it behaves like there would be nothing :/ .. I'm struggling with that for hours now
Try to clear cache, and check if you use app_dev.php front controller to acces to your page. With your web browser you can check the content of your CSS file to see if it's good.
Hi, I have cleared the cache and checked the controller.. everything ok here :/ .. but still the CSS is not accessible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.