symfony - Assetic 和我的 Assets

标签 symfony sass assetic

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

  • 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;

我在 asset:install 之后有这个路径,并且我的文件位于 web/mybundle/fonts 和 web/mybundle/images 下

当我执行 php app/console assetic:dump --env=prod --no-debug

我的网站上有:

  • CSS
  • js(公共(public)文件夹)

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

为什么我的网站上没有所有文件夹?使用/bundles/Mybundle/images/darkGreyBackground.jpg 和/bundles/Mybundle/fonts/billabong-webfont.ttf 调用我的图像和字体是否正确?

最佳答案

这是一种标准且预期的行为,在调用 php app/console assetic:dump 后,包资源的符号链接(symbolic link)位于 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;

编辑

在您的 bundle 中,如果您希望在运行 assets:install 命令后可以在 web 目录中访问文件,则必须将它们放入 Resources/public/ 目录,如下所述:http://symfony.com/doc/current/book/page_creation.html#bundle-directory-structure

关于symfony - Assetic 和我的 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15073559/

相关文章:

php - 如何在命令的类上显示进度条

css - 从 css 到 scss 的 Angular-cli

php - Symfony 2 中 CSS 文件中的资源路径

symfony - 未找到 Assets 路线

javascript - Symfony2 Assetic 无法使用带 * 号的多个 javascript 文件

php - 交响乐 4 : how to use two different environments in my local server

php - Doctrine ManyToMany 同一实体重复输入错误

symfony - 使用 for 循环表示 Twig 中的变量

html - 移动端垂直滚动

css - SCSS mixin 跳过默认参数