global-variable-exists is triggering errors in Sass

后端 未结 1 1326
梦谈多话
梦谈多话 2021-01-14 08:04

I\'m using a ternary-like statement to initialize a variable in Sass. This allows me to set some of my default variables to the same thing that Zurb Foundation is using, but

相关标签:
1条回答
  • 2021-01-14 08:17

    The "problem" persists because you're using the function incorrectly. The docs paint a very clear picture as to how this function is intended to be used:

    $a-false-value: false;
    // global-variable-exists(a-false-value) => true
    
    .foo {
      $some-var: false;
      @if global-variable-exists(some-var) { /* false, doesn't run */ }
    }
    

    See how there are no variables being passed to the function? That's because it expects a string that contains the name of the variable, not the variable itself. Passing in the variable itself would defeat the purpose of the function: you can't pass variables that don't exist to functions or mixins.

    So... just drop the $:

    $nav-link-icon-color: if( global-variable-exists(topbar-link-color), $topbar-link-color, #fff) !default;
    
    0 讨论(0)
提交回复
热议问题