# How do I use conditions to show or hide content?

> Use Liquid if/else conditions in your subject line and email body to show, hide, or change content based on each recipient's spreadsheet data.

SecureMailMerge personalizes your emails with [Liquid](https://liquidjs.com/) templating. Alongside simple tokens like `{{FirstName}}`, you can use **conditions** to show, hide, or change blocks of content based on each recipient's data.

Conditions work in both the **subject line** and the **email body**.

## Basic if / endif

Wrap the content you want to make optional between an opening `{% if %}` tag and a closing `{% endif %}` tag. The condition is checked against the value in the named column for each recipient.

```liquid
{% if Country == "Germany" %}
  Versand erfolgt aus unserem Lager in Berlin.
{% endif %}
```

The block is only included for recipients whose `Country` column equals `Germany`. Everyone else sees nothing in its place.

String values must be wrapped in quotes (`"Germany"` or `'Germany'`). Numbers are written without quotes.

## Capitalization, spaces, and smart quotes don't matter

Conditions are forgiving, so small differences between your template and your spreadsheet won't stop a condition from matching:

- **Column names are case-insensitive.** `{% if new == "TRUE" %}` matches a column headed `New`, `NEW`, or `new`. You don't have to match the exact capitalization of your header.
- **Text comparisons ignore capitalization and surrounding spaces.** A condition like `{% if New == "TRUE" %}` matches a cell containing `TRUE`, `true`, or even `  True `. Values are compared without regard to case or to leading and trailing spaces.
- **Straight and curly quotes are treated the same.** If your editor auto-converts your straight quotes (`"TRUE"`) into curly "smart" quotes (`“TRUE”`), the condition still works.

```liquid
{% if new == "TRUE" %}
  Welcome aboard! Here's what to do first.
{% endif %}
```

The example above matches whether your column is called `New` or `new`, and whether the cell says `TRUE`, `true`, or ` True `.

## Adding an else branch

Use `{% else %}` to provide alternative content when the condition is false.

```liquid
{% if Plan == "Premium" %}
  Thanks for being a Premium customer, your priority support line is +1 555 0100.
{% else %}
  Need a hand? Reply to this email and we'll help out.
{% endif %}
```

## Multiple branches with elsif

Chain several conditions together with `{% elsif %}`. The first matching branch wins.

```liquid
{% if Tier == "Gold" %}
  You've unlocked our Gold benefits.
{% elsif Tier == "Silver" %}
  You're on the Silver plan.
{% else %}
  Welcome aboard!
{% endif %}
```

## Comparison operators

You can compare column values with any of these operators:

| Operator | Meaning |
| --- | --- |
| `==` | equals |
| `!=` | does not equal |
| `>` | greater than |
| `<` | less than |
| `>=` | greater than or equal |
| `<=` | less than or equal |

```liquid
{% if OrderTotal >= 100 %}
  You qualify for free shipping!
{% endif %}
```

## Combining conditions with and / or

Use `and` and `or` to test more than one column at once.

```liquid
{% if Country == "USA" and Plan == "Premium" %}
  Your US Premium perks are active.
{% endif %}
```

## Checking whether a cell has a value

In Liquid an empty cell is still "truthy", so `{% if Notes %}` is **not** a reliable way to check for a value. Use `blank` instead, it matches empty cells and cells that contain only spaces:

```liquid
{% if Notes != blank %}
  A note from your account manager: {{Notes}}
{% endif %}
```

To do the opposite, show content only when a cell is empty, flip the comparison:

```liquid
{% if PhoneNumber == blank %}
  We don't have a phone number on file. Reply to add one.
{% endif %}
```

## Column names with spaces

If your column header contains spaces (or other special characters), reference it with bracket notation, the same way you would in a normal token:

```liquid
{% if ["Account Status"] == "Active" %}
  Your account is in good standing.
{% endif %}
```

For plain merge tokens (outside a condition), you can now also write a header that contains spaces directly, without the brackets: `{{ First Name }}` works the same as `{{ ["First Name"] }}`.

## Matching part of a value with contains

`contains` checks whether a text value includes a substring.

```liquid
{% if Email contains "@gmail.com" %}
  Tip: add us to your Gmail contacts so we don't land in Promotions.
{% endif %}
```

## Inverting a condition with unless

`{% unless %}` is the opposite of `{% if %}`, the block shows only when the condition is **false**.

```liquid
{% unless Country == "USA" %}
  International shipping rates apply.
{% endunless %}
```

## Picking one of many values with case / when

When you need to switch between several fixed values, `{% case %}` is cleaner than a long `elsif` chain.

```liquid
{% case Language %}
  {% when "de" %}
    Vielen Dank für Ihre Bestellung!
  {% when "fr" %}
    Merci pour votre commande !
  {% else %}
    Thank you for your order!
{% endcase %}
```

## Tips

- Conditions can wrap **any** content, text, links, images, or even other tokens.
- Whitespace and line breaks inside `{% if %}` blocks are kept, so place your tags carefully to avoid blank lines in the final email.
- You can combine conditions with the [default value](https://www.securemailmerge.com/help/specify-fallback-default-values-for-mail-merge/) filter for fallback text, and with [date formatting](https://www.securemailmerge.com/help/date-formatting-in-mail-merge/) for dates.
- Always close every tag: `{% if %}` needs `{% endif %}`, `{% unless %}` needs `{% endunless %}`, and `{% case %}` needs `{% endcase %}`. A missing closing tag causes a [liquid syntax error](https://www.securemailmerge.com/help/error-liquid-syntax/).
