# Conditional

> Liquid conditional tags in Shoplazza themes: if, elsif, else, unless and case, and the conditions that decide whether a block of Liquid code runs.

Conditional tags define conditions that determine whether blocks of Liquid code get executed.

## if

Renders an expression if a specific condition is `true`.

```liquid title="Syntax"
{% if condition %}
  expression
{% endif %}
```

* `condition`: The condition to evaluate.
* `expression`: The expression to render if the condition is met.

```liquid title="Code"
{% if product.compare_at_price > product.price %}
  This product is on discount!
{% endif %}
```
```json title="Data"
{
  "product": {
    "compare_at_price": "18.88",
    "price": "12.88"
  }
}
```

```html title="Output"
This product is on discount!
```

## elsif

You can use the `elsif` tag to check for multiple conditions.

```liquid title="Code"
{% if product.type == 'Seafood' %}
	This is a seafood type!
{% elsif product.type == 'Fruit' %}
	This is a fruit type!
{% endif %}
```
```json title="Data"
{
  "product": {
    "type": "Fruit"
  }
}
```

```html title="Output"
This is a fruit type!
```

## else

Allows you to specify a default expression to execute when no other condition is met.

You can use the `else` tag with the following tags:

* [if](./conditional#if)
* [unless](./conditional#unless)
* [case](./conditional#case)

```liquid title="Syntax"
{% else %}
	expression
```

* `expression`: The expression to render if no other condition is met.

```liquid title="Code"
{% if product.available %}
  This product is available!
{% else %}
  This product is sold out!
{% endif %}
```
```json title="Data"
{
  "product": {
    "available": false
  }
}
```

```html title="Output"
This product is sold out!
```

## unless

Renders an expression unless a specific condition is `true`.

:::tip
Similar to the [if tag](./conditional#if), you can use `elsif` to add more conditions to an `unless` tag.
:::

```liquid title="Syntax"
{% unless condition %}
  expression
{% endunless %}
```

* `condition`: The condition to evaluate.
* `expression`: The expression to render unless the condition is met.

```liquid title="Code"
{% unless product.has_only_default_variant %}
  Variant selection functionality
{% endunless %}
```
```json title="Data"
{
  "product": {
    "has_only_default_variant": false
  }
}
```

```html title="Output"
Variant selection functionality
```

## case

Renders a specific expression depending on the value of a specific variable.

```liquid title="Syntax"
{% case variable %}
  {% when first_value %}
    first_expression
  {% when second_value %}
    second_expression
  {% else %}
    third_expression
{% endcase %}
```

* `variable`: The name of the variable you want to base your case statement on.
* `first_value`: A specific value to check for.
* `second_value`: A specific value to check for.
* `first_expression`: An expression to be rendered when the variable's value matches `first_value`.
* `second_expression`: An expression to be rendered when the variable's value matches `second_value`.
* `third_expression`: An expression to be rendered when the variable's value has not match.

```liquid title="Code"
{% case product.type %}
  {% when 'Seafood' %}
    This is a seafood type.
  {% when 'Fruit' %}
    This is a fruit type.
  {% else %}
    This is a food.
{% endcase %}
```
```html title="Data"
{
  "product": {
    "type": "Fruit"
  }
}
```

```html title="Output"
This is a fruit type.
```
