Reputation: 773
I'm using assetic with less in Symfony 2 and the MopaBootstrapBundle.
The dynamically generated css file seems to be valid but styling is not applied. If we dump the assets then it does work in prod, but I don't want to do that in dev as that's against the whole point I thought.
config.yml:
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ MopaBootstrapBundle ]
#java: /usr/bin/java
filters:
cssrewrite: ~
less:
node: /usr/local/bin/node
node_paths: [/usr/local/lib/node_modules]
# auto apply less to all .less files
apply_to: "\.less$"
config_dev.yml
assetic:
use_controller: true
within my template is:
{% stylesheets
'@MopaBootstrapBundle/Resources/public/less/mopabootstrapbundle.less'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen" />
the rendered html is:
<link href="/app_dev.php/css/bab9907_mopabootstrapbundle_1.css" type="text/css" rel="stylesheet" media="screen" />
This file resolves, I can paste the URL into the address bar and see a valid CSS file.
Furthermore if we dump assets in prod it also works
app/console assetic:dump --env=prod
We clear the prod cache and the output is styled. In dev I get zero styling.
I've also ran:
app/console assets:install --symlink web
Installing assets using the symlink option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Mopa\Bundle\BootstrapBundle into web/bundles/mopabootstrap
Installing assets for Symfony\Bundle\WebProfilerBundle into web/bundles/webprofiler
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
All this is ditto Javascript (the files resolve when the URLs are followed)
Am I doing something wrong?
Upvotes: 4
Views: 5616
Reputation: 41
I ran into this too, and i was also using FosRestBundle and had it misconfigured:
fos_rest:
format_listener:
rules:
- { path: '^/', priorities: ['json', 'html'], fallback_format: html, prefer_extension: true }
This rule now applys to EVERY request to the app, and will only know json and html and since .css doesnt match it uses application/json
Correctly it should be:
fos_rest:
format_listener:
rules:
- { path: '^/api', priorities: ['json', 'html'], fallback_format: html, prefer_extension: true }
- { path: '^/', priorities: [ 'html', '*/*'], fallback_format: html, prefer_extension: true }
The last line applies to everything not matched yet, and it tells / use what was matched internally or something similar intelligent.
And voila use_controller: true
works again
Upvotes: 3
Reputation: 11
Th Same thing happened to me so here is how I resolved it
I have changed this assetic setting in config_dev.yml to this
assetic:
use_controller: false
deleted the dev cache and it worked
note: if you are using MAMP then make sure to follow whats in this link
MopaBootstrapBundle less-installation
Upvotes: 0
Reputation: 14568
Did you paste the URL with app_dev.php or without it? If the file really resolves, it should be working, and is not a Sf2 problem. Is your webroot pointing to 'web' dir? If not, try removing the leading '/' in your link href, or change it to the correct path. In dev I usually have something like this:
<link href="http://myapp-static.dev/myapp/web/app_dev.php/css/all.css" media="screen" type="text/css" rel="stylesheet">
I preppended an 'assets_base_url' variable (that I defined in twig globals and parameters.yml) and that was the resulting URL. It would have failed if I used '/app_dev.php/css/all.css' instead, because the browser would interpret it as 'http://myapp-static.dev/app_dev.php/css/all.css'
Upvotes: 0