Last Updated: February 25, 2016
·
505
· rizwaniqbal

Getting parent paths to work in Basset

I build my assets on Laravel 4 using [Basset][1]. Jason has done an excellent job documenting it, but there are a few caveats that slip through and haven't been mentioned.

I use a vanilla CSS stylesheet in my collection and the parent paths to images just won't work. I would get an error because after Basset builds assets, it stores them in a build directory inside your public folder. Even setting paths relative to build did not work.

This is how my collection was written:

'collections' => array(

        'application' => function($collection) {
            $collection->add('../vendor/twitter/bootstrap/less/bootstrap.less')->apply('Less');

            $directory = $collection->directory('assets/stylesheets', function($collection) {
                $collection->add('main.css');
            });

            $directory->apply('UriRewriteFilter');
            $directory->apply('CssMin');
        }
 ),

After wasting a considerable time trying to look for an answer, I found the setArguments method.

'collections' => array(

        'application' => function($collection) {
            $collection->add('../vendor/twitter/bootstrap/less/bootstrap.less')->apply('Less');

            $directory = $collection->directory('assets/stylesheets', function($collection) {
                $collection->add('main.css');
            })->apply('UriRewriteFilter')->setArguments('../')->apply('CssMin');
        }
 ),

This did the trick for me.

[1]: http://jasonlewis.me/code/basset/4.0/