Search code examples
symfonypathlessrelative-pathabsolute-path

Assets paths in LESS using Symfony


Using Symfony2 and LESS, I'm having a hard time to find a nice way to import assets. E.g, if I want to import an asset in my LESS-file located in @bundle/Resources/public/css/file.less, and the asset is located at: /web/assets/vendor/foo/bar.less (considering / as project root).

Using ../../../../../../web/assets/vendor/foo/bar works, which isn't very pretty. /web/assets/vendor/foo/bar doesn't work either, since LESS doesn't know where the project is located.

Are there any prettier solutions than above?


Solution

  • I solved this by switching to Less.php, and then specifying a path in my config.yml. Full example:

    #config.yml
    assetic:
        filters:
            lessphp:
                apply_to: "\.less$"
                paths:
                    - "%kernel.root_dir%/../web"
    

    Which made it possible to use e.g:

    @import 'assets/vendor/foo/bar';