Is there an equivalent of isset or a null coalescing operator in SASS?

Armstrongest

I want to set a variable only if it hasn't been set.

SO...

In _layout.scss:

$page-width: 1100px;

However, in my _module.scss file, I don't want to have a dependency on _layout.scss

I'd like to do something like this :

$page-width = $page-width ?? 960px; 
// If $page-width exists, use it, otherwise set it to a default of 960px;

I'd like something that preferable works in SASS 3.2. I found a solution here, otherwise:

global-variable-exists is triggering errors in Sass

Mohamad

I believe you are looking for variable defaults, and SASS supports them. Variable defaults allow you to assign to variables if they aren't already assigned using ! at the end of the value.

In your case, you can use this in _layout.css:

$page-width: 1100px;

And then in _module.scss you can

$page-width: 960px !default;

This is roughly equivalent to saying assign $page-width to 960px unless $page-width is already defined.

Check out the docs on default variables.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is there an equivalent of isset or a null coalescing operator in SASS?

From Java

Is there a "null coalescing" operator in JavaScript?

From Dev

Null coalescing operator override

From Dev

Null coalescing operator with bool

From Dev

Null coalescing operator and casting with as

From Dev

Null coalescing operator override

From Java

PHP Null coalescing operator usage

From Dev

Null Coalescing Operator in F#?

From Dev

null coalescing operator assignment to self

From Dev

null-coalescing operator in the getter

From Java

PHP ternary operator vs null coalescing operator

From Dev

Usage of ?? operator (null-coalescing operator)

From Dev

Usage of ?? operator (null-coalescing operator)

From Dev

sql null in c# and null coalescing operator

From Dev

null-coalescing operator on a property get

From Dev

Implicit conversion with null-coalescing operator

From Java

What is null coalescing assignment ??= operator in PHP 7.4

From Dev

Is there an equal for the c# null coalescing operator in java?

From Dev

null-coalescing operator with wildcard in a lambda expression

From Dev

Is there a way to implement and make use of a "NOT null coalescing" operator?

From Dev

Is there a way to implement and make use of a "NOT null coalescing" operator?

From Dev

How to define a null-coalescing operator for Twig?

From Dev

Performance of expression behind null coalescing operator

From Dev

Null-coalescing operator returning null for properties of dynamic objects

From Dev

Null propagation + null coalescing operator not working as expected when dealing with InnerException

From Dev

Null propagation + null coalescing operator not working as expected when dealing with InnerException

From Java

Curious null-coalescing operator custom implicit conversion behaviour

From Dev

How does the Null-Coalescing Operator (??) work in Spider?

From Dev

Shorthand for null-coalescing operator and assignment for re-generatable property?

Related Related

  1. 1

    Is there an equivalent of isset or a null coalescing operator in SASS?

  2. 2

    Is there a "null coalescing" operator in JavaScript?

  3. 3

    Null coalescing operator override

  4. 4

    Null coalescing operator with bool

  5. 5

    Null coalescing operator and casting with as

  6. 6

    Null coalescing operator override

  7. 7

    PHP Null coalescing operator usage

  8. 8

    Null Coalescing Operator in F#?

  9. 9

    null coalescing operator assignment to self

  10. 10

    null-coalescing operator in the getter

  11. 11

    PHP ternary operator vs null coalescing operator

  12. 12

    Usage of ?? operator (null-coalescing operator)

  13. 13

    Usage of ?? operator (null-coalescing operator)

  14. 14

    sql null in c# and null coalescing operator

  15. 15

    null-coalescing operator on a property get

  16. 16

    Implicit conversion with null-coalescing operator

  17. 17

    What is null coalescing assignment ??= operator in PHP 7.4

  18. 18

    Is there an equal for the c# null coalescing operator in java?

  19. 19

    null-coalescing operator with wildcard in a lambda expression

  20. 20

    Is there a way to implement and make use of a "NOT null coalescing" operator?

  21. 21

    Is there a way to implement and make use of a "NOT null coalescing" operator?

  22. 22

    How to define a null-coalescing operator for Twig?

  23. 23

    Performance of expression behind null coalescing operator

  24. 24

    Null-coalescing operator returning null for properties of dynamic objects

  25. 25

    Null propagation + null coalescing operator not working as expected when dealing with InnerException

  26. 26

    Null propagation + null coalescing operator not working as expected when dealing with InnerException

  27. 27

    Curious null-coalescing operator custom implicit conversion behaviour

  28. 28

    How does the Null-Coalescing Operator (??) work in Spider?

  29. 29

    Shorthand for null-coalescing operator and assignment for re-generatable property?

HotTag

Archive