# 在主题组件中使用变量结合@if的任何方法吗？

**URL:** <https://meta.discourse.org/t/is-there-any-way-to-use-if-in-a-theme-component-using-a-variable/350236>\
**Category:** Development\
**Created:** [2025年二月3日 13:01 UTC](https://meta.discourse.org/t/is-there-any-way-to-use-if-in-a-theme-component-using-a-variable/350236 "2025-02-03T13:01:45Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [2025年二月3日 13:11 UTC](https://meta.discourse.org/t/is-there-any-way-to-use-if-in-a-theme-component-using-a-variable/350236/2 "2025-02-03T13:11:29Z")

</div>

运行时 CSS 变量（如 `--my-variable`）无法在 SASS/SCSS 构建时 `@if` 语句中使用。

因此，我认为您必须完全在构建时处理此问题，仅限于使用 SCSS 变量。类似这样：

```plaintext
@if $my_boolean_setting_in_theme == "true" {
  ...
}

```

---

_[View the full topic](https://meta.discourse.org/t/is-there-any-way-to-use-if-in-a-theme-component-using-a-variable/350236)._
