首页 文章

资产和我的资产

提问于
浏览
4

我是symfony 2和Assetic的新手 . 我想在我的CSS中使用assetic和Sass . 我使用自定义字体 . 我在我的资源包下创建了资源文件夹“assets / css”,里面我有_base.scss和main.scss . 在我的公共文件夹中,我有:

  • css

  • 字体

  • 图片

  • js

在字体中我有自定义字体 .

在我的SCSS中,我会像这样检索我的字体和图像:

@include font-face("billabongregular", font-files("/bundles/Mybundle/fonts/billabong-webfont.ttf"));
background: $bg_header url("/bundles/Mybundle/images/darkGreyBackground.jpg") fixed no-repeat top center;

我在资产之后有这条路径:安装,我的文件在web / mybundle / fonts和web / mybundle / images下

我做的时候 php app/console assetic:dump --env=prod --no-debug

我在我的网站上:

  • css

  • js(公共文件夹)

但我没有Fonts文件夹和图像文件夹 . 如果IO看到图像中的源代码我有这个路径/bundles/Mybundle/images/darkGreyBackground.jpg

为什么我没有网络中的所有文件夹?是不是用/bundles/Mybundle/images/darkGreyBackground.jpg和/bundles/Mybundle/fonts/billabong-webfont.ttf调用我的图像和我的字体?

2 回答

  • 1

    这是一种标准和预期的行为,在您调用 php app/console assetic:dump 命令后,您的包的资源的符号链接在 web/bundles/Mybundle/ 之下 .

    要在css中使用资产生成路径,您可以使用 cssrewrite 过滤器,或者更简单,您的 cssimages 文件夹位于同一主文件夹中,使用相对路径:

    @include font-face("billabongregular", font-files("../fonts/billabong-webfont.ttf"));
    background: $bg_header url("../images/darkGreyBackground.jpg") fixed no-repeat top center;
    

    EDIT

    在捆绑包中,如果要在运行 assets:install 命令后在 web 目录中访问文件,则必须将它们放在 Resources/public/ 目录中,如下所示:http://symfony.com/doc/current/book/page_creation.html#bundle-directory-structure

  • -1

    我有同样的问题,我只是尝试使用以下作为解决方法 . 到目前为止似乎工作 .

    {% stylesheets
        output='assets/fonts/glyphicons-halflings-regular.ttf'
        'bundles/bootstrap/fonts/glyphicons-halflings-regular.ttf'
    %}{% endstylesheets %}
    

    请注意省略任何输出,这意味着模板上没有显示任何内容 . 当我运行assetic时:转储文件被复制到所需位置,css包含按预期工作 .

相关问题