Videl Videl - 1 month ago 7
Sass (Sass) Question

Sass - How to Import a Message into Directive

I use

@warn
a lot, but I'd like to import pre-written messages into my warnings that are stored for example in another function or file.

Is this possible?

I know the following won't work, but so you get the idea...

@if $a == 'red' {
color: red;
} @else if $a == 'blue' {
color: blue;
} @else {
@warn '@include error-msg_no-color-detected';
}

Answer

This can be done using variables...

$msg: 'Something went wrong!';

@if ... {
    ...
} @else {
    @warn: '#{$msg}';
}

This allows me to create a _debug.scss file containing lots of messages.

@import 'config';
@import 'debug';
@import 'dark';
@import 'application';

_debug.scss:

@msg-1: 'Oops!';
@msg-2: 'No color defined. Check the config file.';