Assetic paths in Symfony 2 dev. Ways work but style doesn't apply

I use assetic with less in Symfony 2 and MopaBootstrapBundle.

The dynamically generated css file seems valid, but the style is not applied. If we dump assets, then it works in prod, but I do not want to do it in dev as it is against everything that 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 

inside my template:

 {% stylesheets '@MopaBootstrapBundle/Resources/public/less/mopabootstrapbundle.less' %} <link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen" /> 

displayed html:

  <link href="/app_dev.php/css/bab9907_mopabootstrapbundle_1.css" type="text/css" rel="stylesheet" media="screen" /> 

This file permits, I can paste the URL into the address bar and see the actual CSS file.

In addition, if we dump assets in prod, it also works

 app/console assetic:dump --env=prod 

We clear the prod cache, and the output is in style. In dev, I get a null style.

I 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 

None of this is Javascript (files are resolved using URLs)

Am I doing something wrong?

+4
source share
3 answers

I came across this too, and I also used the FosRestBundle and configured it incorrectly:

 fos_rest: format_listener: rules: - { path: '^/', priorities: ['json', 'html'], fallback_format: html, prefer_extension: true } 

This rule now applies to EVERY request for the application and will only know json and html, and since .css does not match it, it uses application / json

Correctly this 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 refers to everything that has not yet been agreed upon, and it reports / uses what has been agreed upon internally or something similar intelligent. And use_controller: true works again

+3
source

Did you embed the url with or without app_dev.php? If the file really solves, it should work and is not an Sf2 problem. Does your website point to a "web directory"? If not, try removing the leading "/" in your href link or changing 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 prepared the variable 'asset_base_url' (which I defined in glibals twig and parameters.yml), and that was the resulting URL. This would be unsuccessful if I were to use '/app_dev.php/css/all.css' because the browser would interpret it as "http://myapp-static.dev/app_dev.php/css/all.css"

0
source

The same thing happened to me, this is how I resolved it.

I changed this setting in config_dev.yml to this

 assetic: use_controller: false 

deleted the developers cache and worked

Note: if you use MAMP, be sure to follow the instructions in this link

MopaBootstrapBundle less-installation

0
source

All Articles