1

I cant link my style in Symfony.

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

My CSS file is in assets dir

  • yes i have allready downloaded asset from symfony
  • yes i have tried change directories
3
  • Do you see any errors at all? Commented Mar 14, 2018 at 21:01
  • clear cache (delete folder var/cache/* or php bin/console c:c -e prod) Commented Mar 14, 2018 at 22:03
  • If you don't use symfony encore for managing your assets, store them in your public dir. And call your assets with : {{ asset('styles/css/global.min.css') }} (where your styles dir is in public) Commented Mar 15, 2018 at 8:22

2 Answers 2

1

In SF3, you should store your assets in

Store your assets in the web/ directory.

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

In SF4, you should store your assets in

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

and use Webpack Encore to compile, combine and minimize web assets.

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

This is my configuration (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)
        ....

In twig :

    <a href="{{ path('homepage') }}" class="logo" style="background-image:url({{ asset('logo.svg', 'app_img') }})"></a>
Sign up to request clarification or add additional context in comments.

Comments

0

Your assets must be in the Asset folder before compiling them. The compiled version should be in the web folder (SF 3 without flex) or in the public folder (sf4 with flex)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.