# Condition

**Condition** tags are useful for making decisions about what code to run, based on some specific value under inspection.

Often, condition tags are concerned with whether a value is **truthy** or **falsey**. In Liquid, only the values `false` and `nil` are falsey; all other values are truthy.

{% hint style="info" %}
For further discussion on how Liquid treats values, see their documentation: [Truthiness and falsiness in Liquid](https://shopify.dev/docs/themes/liquid/reference/basics/true-and-false).
{% endhint %}

## if

An `if` tag is always paired with an `endif` tag. The code between these tags only runs if the condition in the `if` tag evaluates to something truthy.

```liquid
{% if options.test_mode__boolean %}
  {% action "echo" summaries %}
{% endif %}
```

## unless

Identical in style to the `if` tag, the `unless` tag only executes the code it contains if the condition is falsey.

```liquid
{% unless options.default_tracking_url_template contains "TRACKING_NUMBER" %}
  {% error %}{{ "Placeholder 'TRACKING_NUMBER' is missing." | json }}{% enderror %}
{% endunless %}
```

## else

An `else` tag can be added within `if`, `unless`, and `case` blocks. The code that follows the `else` tag is run if the condition above it does not run.

```liquid
{% if customer.email != empty %}
  {% assign email = customer.email %}
{% else %}
  {% log "Customer had no email" %}
{% endif %}
```

```liquid
{% unless customer.email == empty %}
  {% assign email = customer.email %}
{% else %}
  {% log "Customer had no email" %}
{% endif %}
```

## elsif

An `elsif` tag adds a second condition to an `if` or `unless` block. If the condition above it does not run, the next `elsif` tag will be evaluated – and if its condition is truthy, the code that follows it will run.

Any number of `elsif` tags may be added within `if` or `unless` blocks.

```liquid
{% assign today = "tuesday" %}

{% if today == "monday" %}
  {% log "it's monday!" %}
{% elsif today == "tuesday" %}
  {% log "it's tuesday!" %}
{% endif %}
```

```liquid
{% assign today = "tuesday" %}

{% unless today == "tuesday" %}
  {% log "it's not tuesday!" %}
{% elsif today == "tuesday" %}
  {% log "it's tuesday!" %}
{% endif %}
```

## case, when

The `case` and `endcase` tag pair contain a series of `when` tags, and optionally an `else` tag. The value specified in the `case` tag is inspected, and Liquid then looks for a `when` tag that has a matching value. If one is found, that `when` tag gets to run its code. If no match is found, the code for the `else` tag (if given) is run.

```liquid
{% case order.cancel_reason    %}
  {% when "customer" %}
    {% assign cancel_reason = "It was the customer." %}
  {% when "fraud" %}
    {% assign cancel_reason = "It was fraud!" %}
  {% when "inventory" %}
    {% assign cancel_reason = "It was due to inventory issues." %}
  {% else %}
    {% assign cancel_reason = "It was something unknown." %}
{% endcase %}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.mechanic.dev/platform/liquid/basics/control-flow/condition.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
