Can't figure out how the symfony assets works in combination with lessphp

时间:2015-07-28 22:16:53

标签: twitter-bootstrap symfony less php-5.6

I just started to work into symfony framework. I created an starting app with symfony and wanted to install bootstrap 3.3.5 with it. Bit I figured out that it is not working as expected. As the next step I installed Leafo Less.php. To add support for bootstrap > 3.2 I installed oyejorge/less.php with wrapper for the leafo lessc compiler.

I registered it in config.yml with the following lines:

Assetic Configuration

assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]
    #java: /usr/bin/java
    filters:
        lessphp:
            file: %kernel.root_dir%/../src/HomeBundle/Assets/Filter/lessc.php
            apply_to: "\.less$"
            # Formatter options: compressed, lessjs, classic
            formatter: "compressed"
            preserve_comments: false
        cssrewrite: ~

so far the commands work. Next step was, according to the explanations at http://isometriks.com/using-less-with-symfony2 telling me I need to references the style sheet. So I added into the template the content:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>{% block title %}Welcome!{% endblock %}</title>
        {% block stylesheets %}{% endblock %}
        <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
        {% stylesheets '@HomeBundle/Resources/less/bootstrap.less' %}
            <link rel="stylesheet" href="{{ asset_url }}">
        {% endstylesheets %}
    </head>
    <body>
        {% block body %}{% endblock %}
        {% block javascripts %}{% endblock %}
    </body>
</html>

Everytime that I call the controller I get the message:

An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_assetic_5bb3373_0" as such route does not exist.") in base.twig at line 8.

Don't know what I'm doing wrong. Where is my mistake? Any help is appreceated.

1 个答案:

答案 0 :(得分:1)

使用Assetic时,您需要使用&#34; app / console assetic:dump&#34;命令生成css / less / js文件。这也将它们复制到Web文件夹以使其可访问。

调用此命令后,请检查web / css文件夹以查看编译的less是否在那里。

如果您没有在开发环境中运行(使用网址中的app_dev.php),则需要在运行命令时指定生产环境&#34; app / console assetic:dump --env = prod&# 34;