---
title: ValidVisibleIf
description: >-
  Identifies malformed visible_if expressions and references to settings that
  don't exist.
source_url:
  html: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/valid-visible-if
  md: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/valid-visible-if.md
api_name: liquid
---

# ValidVisibleIf

Identifies invalid [`visible_if`](https://shopify.dev/docs/storefronts/themes/architecture/settings#conditional-settings) expressions in settings. A `visible_if` value needs to be a Liquid expression wrapped in `{{ }}`, such as `{{ block.settings.show_icon }}`, and each variable that it references needs to exist.

This check covers the `visible_if` of each setting in the `settings` array of a section or theme block schema, and of each setting in `config/settings_schema.json`. The variables that an expression can reference depend on the file:

| File | Valid references |
| - | - |
| Section | `section.settings.<id>` for the section's settings, `settings.<id>` for theme settings, and variables assigned in the file |
| Theme block | `block.settings.<id>` for the block's settings, `section.settings.<id>` for the settings of the section that contains the block, `settings.<id>` for theme settings, and variables assigned in the file |
| `config/settings_schema.json` | `settings.<id>` for theme settings |

Theme settings are the settings defined in `config/settings_schema.json`. In a theme block, Theme Check doesn't check references to `section`, because the block can be used in different sections.

Theme Check reports the following problems:

* A value that doesn't contain a `{{ }}` expression.
* An expression that can't be parsed.
* An expression that doesn't reference any variable, such as `{{ "some random string" }}`. The expressions `{{ true }}` and `{{ false }}` are valid.
* A reference to a setting or variable that doesn't exist.
* A reference to `block` outside a theme block file, or to `section` in `config/settings_schema.json`.
* A reference that uses a namespace as a value, such as `{{ block.settings }}`, or uses a value as a namespace, such as `{{ block.settings.show_icon.size }}`.

***

## Examples

The following examples contain code snippets that either fail or pass this check.

### ✗ Fail

In the following example, the block doesn't have a `show_icons` setting, so Theme Check reports `Invalid variable: "block.settings.show_icons" was not found.`:

## blocks/button.liquid

```liquid
{% schema %}
{
  "name": "Button",
  "settings": [
    {
      "type": "checkbox",
      "id": "show_icon",
      "label": "Show icon",
      "default": false
    },
    {
      "type": "text",
      "id": "icon_label",
      "label": "Icon label",
      "visible_if": "{{ block.settings.show_icons }}"
    }
  ]
}
{% endschema %}
```

In the following example, a section references `block`, so Theme Check reports `Invalid visible_if: can't refer to "block" when not in a block file.`:

## sections/hero.liquid

```liquid
{% schema %}
{
  "name": "Hero",
  "settings": [
    {
      "type": "checkbox",
      "id": "show_button",
      "label": "Show button",
      "default": true
    },
    {
      "type": "text",
      "id": "button_label",
      "label": "Button label",
      "visible_if": "{{ block.settings.show_button }}"
    }
  ]
}
{% endschema %}
```

In the following example, the expression isn't wrapped in `{{ }}`, so Theme Check reports `Invalid visible_if expression. It should take the form "{{ <expression> }}".`:

## sections/hero.liquid

```liquid
{% schema %}
{
  "name": "Hero",
  "settings": [
    {
      "type": "checkbox",
      "id": "show_button",
      "label": "Show button",
      "default": true
    },
    {
      "type": "text",
      "id": "button_label",
      "label": "Button label",
      "visible_if": "section.settings.show_button"
    }
  ]
}
{% endschema %}
```

### ✓ Pass

In the following example, the section references its own setting:

## sections/hero.liquid

```liquid
{% schema %}
{
  "name": "Hero",
  "settings": [
    {
      "type": "checkbox",
      "id": "show_button",
      "label": "Show button",
      "default": true
    },
    {
      "type": "text",
      "id": "button_label",
      "label": "Button label",
      "visible_if": "{{ section.settings.show_button }}"
    }
  ]
}
{% endschema %}
```

In the following example, a theme setting references another theme setting:

## config/settings\_schema.json

```json
[
  {
    "name": "Cart",
    "settings": [
      {
        "type": "checkbox",
        "id": "show_cart_note",
        "label": "Show cart note",
        "default": false
      },
      {
        "type": "text",
        "id": "cart_note_label",
        "label": "Cart note label",
        "visible_if": "{{ settings.show_cart_note }}"
      }
    ]
  }
]
```

***

## Options

The following example contains the default configuration for this check:

```yaml
ValidVisibleIf:
  enabled: true
  severity: error
```

| Parameter | Description |
| - | - |
| `enabled` | Whether this check is enabled. |
| `severity` | The [severity](https://shopify.dev/docs/storefronts/themes/tools/theme-check/configuration#check-severity) of the check. |

***

## Disabling this check

Disabling this check isn't recommended.

***
