# Sass variables are not being read in code

**URL:** https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588
**Category:** Development
**Created:** [February 28, 2023, 11:52pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588 "2023-02-28T23:52:09Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [February 28, 2023, 11:52pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588/1 "2023-02-28T23:52:09Z")

</div>

Hello,

When adding more settings to my theme, it started to become apparent Discourse was ignoring them.

Code:

```scss

#main-outlet-wrapper .sidebar-wrapper {
  @if $Full_Width == true {
    left: 10px;
  }
}

@if $Full_Width == true {
  :root {
    --d-max-width: 95%;
  }
  #main-outlet {
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
    margin-top: 5px;
    margin-bottom: 50px;
  }
}

```

This code doesn’t do anything, no matter the value of the setting.

However, if I remove `== true`, it’ll always be enabled no matter what.

This also seems to be the issue with any other bool? I read the sass docs and my code matches and it still does not work.

```scss

div#main-outlet.wrap.not-found-container,
#main-outlet-wrapper {

  #main-outlet,
  .sidebar-wrapper {
    @if $Is_Background_Blurred {
      backdrop-filter: blur(3rem) !important;
      background-color: #0a0a0aa6 !important;

      input[type],
      .select-kit.combo-box .select-kit-header,
      .d-editor-textarea-wrapper,
      div.ac-wrap {
        background: transparent;
      }
    }

    @else {
      backdrop-filter: none !important;
      background-color: var(--secondary) !important;

      input[type],
      .select-kit.combo-box .select-kit-header,
      .d-editor-textarea-wrapper,
      div.ac-wrap {
        background: transparent;
      }
    }
  }
}

```

Thanks for any help.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 2, 2023, 10:32pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588/2 "2023-03-02T22:32:30Z")

</div>

I encountered the same issue a few weeks ago and concluded that the `if` SASS condition wasn’t working as I thought. I’d be very happy to know if such a thing is possible though:

Having “if this site\_setting == value then” in a SASS file.

I’m just putting this here in case it would be of any usefulness:

> **[Sass: @if and @else](https://sass-lang.com/documentation/at-rules/control/if/)**
>
> Syntactically Awesome Style Sheets

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [March 2, 2023, 10:40pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588/3 "2023-03-02T22:40:59Z")

</div>

> [@Canapin](#):
>
> [Sass: @if and @else](https://sass-lang.com/documentation/at-rules/control/if)

I had a look here before I made my post, and my code is the exact same.

Doing `@if $var {}` will always run it no matter the value, and `@if $var == true {}` will never run it.

---

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [March 2, 2023, 10:48pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588/4 "2023-03-02T22:48:30Z")

</div>

Have you tried:

`@if $var == "true"`

It’s possible the boolean is actually a string, I’ve run into this with theme components before.

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [March 2, 2023, 10:55pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588/5 "2023-03-02T22:55:39Z")

</div>

Yep, seemed to fix it, strange.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 2, 2023, 11:11pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588/6 "2023-03-02T23:11:44Z")

</div>

Awesome, you both helped me figure out a thing I had given up on in one of my theme components. :v:

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [March 2, 2023, 11:13pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588/7 "2023-03-02T23:13:00Z")

</div>

This may fix the dark theme switching we discussed recently, thanks.

It was not working as is.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 2, 2023, 11:33pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588/8 "2023-03-02T23:33:24Z")

</div>

And just like that, Kris helped an entire population.

![](https://global.discourse-cdn.com/meta/original/4X/8/f/d/8fdad09175f2e578688a5a7ae2d2cb9988cb491d.gif)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 1, 2023, 11:33pm UTC](https://meta.discourse.org/t/sass-variables-are-not-being-read-in-code/256588/9 "2023-04-01T23:33:56Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
