Can variables be used in import statements for Sass files?

Solution 1:

You can't use conditional stuff for imports in SASS.

Consider creating a Compass extension out of your project.

Solution 2:

You cannot use variables in import paths as already mentioned. What you can do is use the -I or --load-path option to specify a directory to search from.

sass --watch sass/:css/ --load-path ../../path/to/library/

Let's say you have a directory structure like this:

themes
    hotdog
        _variables.scss
    classic
        _variables.scss
styles.scss

Your styles.scss should have import paths that are relative to the provided load-path(s):

// note the import here doesn't contain themes, hotdog, or classic
@import "variables"; 

@debug $foo;

Your commands would look something like this:

# hotdog
sass styles.scss hotdog.css --load-path ./themes/hotdog/
# classic
sass styles.scss classic.css --load-path ./themes/classic/

See the Sass options documentation for more information.