Symfony从模板加载资产

时间:2018-03-14 20:17:50

标签: css symfony assets

我无法将自己的风格与Symfony联系起来。

<link rel="stylesheet" href="{{ asset('assets/styles/css/global.min.css') }}" />

我的CSS文件位于资产目录

  • 是的,我已经从symfony下载了资产
  • 是的,我尝试过更改目录

2 个答案:

答案 0 :(得分:1)

在SF3中,您应该将资产存储在

Store your assets in the web/ directory.

https://symfony.com/doc/3.4/best_practices/web-assets.html

在SF4中,您应该将资产存储在

Store your assets in the assets/ directory at the root of your project.

并使用Webpack Encore编译,组合和最小化Web资产。

https://symfony.com/doc/current/best_practices/web-assets.html

这是我的配置(SF3): config_dev.yml

framework:
# Assets CDN & dev paths
# change here and in the config_prod.xml
assets:
    packages:
        avatar:
            base_path: upload/members/pics/
        app_css:
            base_path: css/
        app_img:
            base_path: img/
        ....

config_prod.yml - if you want to use CDN

framework:
# Assets CDN & dev paths
# change here and in the config_prod.xml
assets:
    packages:
        avatar:
            base_path: xx.xx.xx.xx/upload/members/pics/ (IP Address of CDN)
        app_css:
            base_path: xx.xx.xx.xx/css/(IP Address of CDN)
        app_img:
            base_path: xx.xx.xx.xx/img/ (IP Address of CDN)
        ....

在树枝上:

    <a href="{{ path('homepage') }}" class="logo" style="background-image:url({{ asset('logo.svg', 'app_img') }})"></a>

答案 1 :(得分:0)

在编译资产之前,您的资源必须位于“资源”文件夹中。编译版本应该在Web文件夹(SF 3没有flex)或公共文件夹(sf4 with flex)