config.yml:
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ FrontendBundle ]
#java: /usr/bin/java
ruby: /usr/bin/ruby
sass: /usr/bin/sass
read_from: %kernel.root_dir%/../../web/
write_to: %kernel.root_dir%/../../web/
filters:
cssrewrite: ~
scss:
style: 'expanded'
compass: true
apply_to: "\.scss$"
compass:
bin: /usr/bin/compass
images_dir: %kernel.root_dir%/../../src/FrontendBundle/Resources/assets/images
generated_images_path: %kernel.root_dir%/../../src/FrontendBundle/Resources/public/images/sprites
http_generated_images_path: /images/sprites
Template:
<?php foreach ($view['assetic']->stylesheets(
array('@FrontendBundle/Resources/assets/scss/homepage.scss'),
array('compass'),
array('output' => 'css/homepage.css')
) as $url):
$styles[] = '<link rel="stylesheet" href="'. $view->escape($url) .' " />' ?>
<?php endforeach; ?>
Prod environment works just fine. css/homepage.css is generated, and there is link to it in result html.
Problems are with dev environment. If I try to generate css dynamically i get "Unable to generate a URL for the named route..." error, with "bundles" option set in config_dev.yml and assetic routes in roting_dev.yml. This is only solutions I found for this issue, none of them worked.
If I try to do prod-like, with setting "use_controller" to false, in result html I get link to "homepage_homepage_1.css" instead of "homepage.css", which is not generated.
Have you tried the new Asset component for Symfony 2.7?
app/config/config.yml
framework:
assets:
version: 'v5'
version_format: '%%s?version=%%s'
base_path: ~
base_urls: ['http://cdn.example.com', 'https://secure.example.com']
packages:
scss:
base_path: bundles/mybundle/scss
compass:
base_path: bundles/mybundle/compass
Then you should recall the correct stylesheet with something like that:
{{ asset('myscss.css', 'scss') }}
{# /bundles/mybundle/scss/myscss.css #}
{{ asset('mycompass.css', 'compass') }}
{# /bundles/mybundle/compass/mycompass.css #}
I suggest you to use Twig on your views so you could filter your variables through an if statement (like assetic
).