簡體   English   中英

如何在 css 文件中使用樹枝資產?

[英]How to use twig asset in a css file?

所以我想使用css導入字體。 我知道如何在 twig/html 頁面中使用 {{ asset('')}} ! 但我不知道如何在 CSS 文件中做到這一點!

當前的 css 文件代碼是:

@font-face {
  font-family: 'porta';
  src: url("../fonts/pluton.eot?49924914");
  src: url("../fonts/pluton.eot?49924914#iefix") format("embedded-opentype"),
       url("../fonts/pluton.woff?49924914") format("woff"),
       url("../fonts/pluton.ttf?49924914") format("truetype"),
       url("../fonts/pluton.svg?49924914#porta") format('svg);
  font-weight: normal;
  font-style: normal;
}

我做了什么 :

@font-face {
  font-family: 'porta';
  src: url("{{ asset('../fonts/pluton.eot?49924914') }}");
  src: url("{{ asset('../fonts/pluton.eot?49924914#iefix') }}") format("embedded-opentype"),
       url("{{ asset('../fonts/pluton.woff?49924914') }}") format("woff"),
       url("{{ asset('../fonts/pluton.ttf?49924914') }}") format("truetype"),
       url("{{ asset('../fonts/pluton.svg?49924914#porta') }}") format("svg");
  font-weight: normal;
  font-style: normal;
}

我添加了這樣的資產,但我沒有工作! 那么如何正確地將它添加到 CSS 文件中呢?

asset() 是一個twig函數,你不能在 css 文件中使用 twig 函數。 如果你想捆綁你的資源,比如圖像、字體、css、js 等,例如使用webpack或者如果你使用 php >= 7.1 使用webpack encore

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM