我已经阅读了很多关于此的帖子,但无法将其用于我的项目。
所以基本上我有一个 Symfony2 项目,其中包括 twitter bootstrap (v3)。在开发模式下一切正常,但是当我在生产模式下尝试时,我收到错误消息,提示无法找到 twitter Bootstrap 字体:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/Symfony/css/fonts/glyphicons-halflings-regular.woff
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/Symfony/css/fonts/glyphicons-halflings-regular.ttf
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/Symfony/css/fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular
这是正常的,因为我在 Symfony/中没有 css/文件夹
项目结构如下:
app/
src/
vendor/
web/
css/
compiled/
fonts/
js/
Twig 文件:
{% block stylesheets %}
{% stylesheets output="css/compiled/main.css" filter='cssrewrite'
'css/bootstrap.min.css'
'css/general.css'
'css/navigation.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
我用过:
php app/console assetic:dump --env=prod
我检查了 bootstrap.min.css(在 web/css/compiled 中)文件(prod 和 dev),它们都具有相同的字体路径。类似于 (../../../fonts/fontName.ext)。
如果我们查看路径,它既不应该在开发模式也不在生产模式下工作,因为路径将字体/文件放在 web 目录之外。然而,它在开发模式下工作。
关于如何解决这个问题的任何想法?
我会很感激。
最佳答案
如果您使用“cssrewrite”过滤器,它会像 Maxoo 所说的那样重写字体文件的路径(到它们的原始来源)。
您可以通过以下方式添加字体文件的 Assets 路径(因此它们被复制到 css/fonts/
文件夹,css 文件将使用原始 ../fonts/
路径)
我使用了以下解决方案:
config.yml:
assetic:
debug: %kernel.debug%
use_controller: false
assets:
bootstrap_fonts_woff:
inputs:
- 'original/path/to/bootstrap/fonts/glyphicons-halflings-regular.woff'
output: fonts/glyphicons-halflings-regular.woff
bootstrap_fonts_ttf:
inputs:
- 'original/path/to/bootstrap/fonts/glyphicons-halflings-regular.ttf'
output: fonts/glyphicons-halflings-regular.ttf
bootstrap_fonts_svg:
inputs:
- 'original/path/to/bootstrap/fonts/glyphicons-halflings-regular.svg'
output: fonts/glyphicons-halflings-regular.svg
bootstrap_fonts_eot:
inputs:
- 'original/path/to/bootstrap/fonts/glyphicons-halflings-regular.eot'
output: fonts/glyphicons-halflings-regular.eot
然后调用
php app/console assetic:dump --env=prod
这应该将文件导出到您的网络文件夹中的字体目录。
希望这对您有所帮助!
关于php - 在 Symfony2 的产品中使用 assetic 时找不到 Twitter Bootstrap glyphicons 字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25864784/