@font-face rule in CSS files in Synmfony 2 with Assetic

@font-face rule in CSS files in Synmfony 2 with Assetic

我正在寻找使用 Assetic 在 Symfony 中包含来自 CSS 文件的字体。问题是浏览器无法加载这些字体。

@font-face {
font-family: 'Corbert'; /*a name to be used later*/
src:    url('fonts/Corbert-Regular.otf')  format('opentype'),
        url('fonts/Corbert-Regular.woff') format('woff'),
        url('fonts/Corbert-Regular.ttf') format('truetype');
}

我的路径结构是

...  
+-src/  
| +-MyCompany/  
|   +-MyBundle/  
|     +-Resources/  
|       +-public/  
|         +-css/  
|           +-fonts/  

我链接 CSS 文件的路径是

我做错了什么?

我找到了解决方案:

只需将 Document.html.twig 放入 link 您的 css 文件的位置:

<style type="text/css">
  @font-face {
  font-family: 'Corbert'; 
  src:    url({{asset('fonts/Corbert-Regular.otf')}}) format('opentype'), 
    url({{asset('fonts/Corbert-Regular.woff')}}) format('woff'),
    url({{asset('fonts/Corbert-Regular.otf')}}) format('truetype');
  }
</style>

确实,如果您将其放入 css 文件中,symfony 似乎无法识别该代码。图片也是一样的:

<style type="text/css">
  body, html{
    background-image:url({{ asset('images/wallpaper.png') }});
  }
<style>

周末愉快!