Assetic, twitter bootstrap and less

4

配置:

assetic:
    debug:          %kernel.debug%
    use_controller: false
    read_from:      %kernel.root_dir%/../public
    filters:
        less:
            node: /usr/bin/node
            node_paths: [/usr/local/lib/node_modules]

Twig模板:

{% block stylesheets %}
{% stylesheets filter='less'
    '@MyBundle/Resources/public/bootstrap/less/bootstrap.less'
%}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}

这个几乎很好用。

我有一个问题,就是没有图片,它们被引用为相对路径("../img/glyphicons-halflings.png")但是它们并不存在。

还有一个问题,如果我在生产服务器上没有node.js,那么它能正常工作吗?如果我只上传已编译的css文件,会起作用吗?

1个回答

4
我认为您也应该使用cssrewrite过滤器,像这样:

{% block stylesheets %}
{% stylesheets filter='less,cssrewrite'
    '/bundles/mybundle/bootstrap/less/bootstrap.less'
%}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}

不要忘记使用以下命令发布您的资源:
app/console assets:install --symlink web

上传已编译的CSS文件即可解决问题。

谢谢!有没有文档可以让我看看如何配置这个过滤器? - umpirsky
我不记得在哪里找到它了...只需要在你的config.yml文件中添加cssrewrite: ~就可以启用它。 - greg0ire
现在它用 url("../Resources/public/bootstrap/img/glyphicons-halflings.png") 引用它,这是一个好的方向,但仍然是404。谢谢。 - umpirsky
是的,它可以工作,谢谢,但只有当我将Twitter Bootstrap复制到“/public/bundles/…”时,它才能工作。我想将其存储在我的bundle内部。这可能吗? - umpirsky
哇,不知道还有那个选项,谢谢!实际上,它可以带或不带 --symlink 选项运行,只要保证将它们转储出来即可。 - umpirsky
显示剩余5条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接