> For the complete documentation index, see [llms.txt](https://kb.craftformswp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kb.craftformswp.com/documentation/form-building/create-form/conditional-text.md).

# Conditional Text and Fallbacks

Show a sentence, a paragraph or a whole block only for some answers, and choose what a tag shows when its value is empty. One email template can then say "A technician will call you about the repair" to one customer and "We'll send you an installation quote" to another, and greet someone who left the name empty with "Hi there" instead of "Hi ,". The same rules work in emails, PDFs, the [Confirmation](/documentation/form-building/create-form/blocks/confirmation.md) message and InfoBlocks.

![The same Confirmation for a visitor who picked "Just a question": only the matching sentence is shown](https://97821998-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FM2yV1foUgoGHBC66VBDw%2Fuploads%2F4DTLFxk31sTUhjjv9Dlj%2Fconditional-text--question-answer-result.jpg?alt=media)

### What you need

* Conditional text, block-level **Show if** and fallback values work in the free version.
* A form with named fields. Conditions use the field names and option values you set on the form.

### Where it works

| Place                                                                                   | `{{#if}}` text | Block **Show if**     | `{{tag\|fallback}}` |
| --------------------------------------------------------------------------------------- | -------------- | --------------------- | ------------------- |
| Email templates (texts, subject)                                                        | Yes            | Yes                   | Yes                 |
| PDF templates                                                                           | Yes            | Yes                   | Yes                 |
| Send Email action settings (Send To, Subject, Body, Reply To, From)                     | Yes            | –                     | Yes                 |
| [Confirmation](/documentation/form-building/create-form/blocks/confirmation.md) message | Yes            | Yes, blocks inside it | Yes                 |
| InfoBlock (updates as the visitor answers)                                              | Yes            | Yes, blocks inside it | Yes                 |
| Option annotations and Value Presets badges                                             | Yes            | –                     | Yes                 |
| Page tags in a form (`post.`, `user.`, `query.`, `meta.`, `site.`, `date.`)             | –              | –                     | Yes                 |

### Show text only for some answers

Wrap the text in `{{#if …}}` and `{{/if}}`:

```
{{#if service == 'repair'}}A technician will call you within 24 hours.{{/if}}
```

Add other cases with `{{else if …}}` and a last one with `{{else}}`. The first condition that matches wins:

```
{{#if service == 'repair'}}A technician will call you within 24 hours.
{{else if service == 'install'}}We'll email you an installation quote.
{{else}}We'll answer your question soon.{{/if}}
```

Sections can be nested, one inside another.

#### Write a condition

Conditions use the same expression language as [Field Conditions](https://kb.craftformswp.com/documentation/form-building/create-form/form-settings-post-context/field-conditions):

| You want                                              | Write                                                               |
| ----------------------------------------------------- | ------------------------------------------------------------------- |
| An answer is a given option                           | `service == 'repair'`                                               |
| An answer is not a given option                       | `service != 'question'`                                             |
| A number is above, below or equal to a value          | `size > 3`, `size <= 10`, `width > height`                          |
| A text field was filled in                            | `company != ''`                                                     |
| Both conditions                                       | `service == 'repair' && size > 3`                                   |
| Either condition                                      | `service == 'repair' \|\| service == 'install'`                     |
| Group conditions                                      | `(service == 'repair' \|\| service == 'install') && when == 'asap'` |
| A checkbox group (or multi-select) includes an option | `includes('gift', extras)`                                          |

Good to know:

* Use the **field name** (`service`), not its label ("Choose one"). Smart variables work by name too.
* Use the **option value** (`'repair'`), not its label ("A repair"). Labels can be changed or translated; values stay the same.
* Put text values in quotes, single or double. Numbers go without quotes.
* For checkbox groups, use `includes()`, never `==`.
* A condition that can't be worked out (a typo, a field that doesn't exist) counts as false. The section is hidden; the email is still sent.

#### Let CraftForms write the condition

You don't need to type conditions. In an InfoBlock, a Confirmation, or an email or PDF template:

1. Select the text that should depend on an answer.
2. In the text toolbar, open **More (⌄)** and choose **Show if…**.
3. In **Show only if…**, choose a field, how to compare (for example **is one of**) and the option or value. Use **Add condition** to combine several.
4. Click **Insert condition**.

The selected text is wrapped in `{{#if …}}…{{/if}}`. With nothing selected, a placeholder text is inserted inside the condition for you to replace.

In email and PDF templates, pick the form in the **Dynamic Data** panel first, so the window can list its fields.

![The Show only if window with a condition on the Choose one field](https://97821998-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FM2yV1foUgoGHBC66VBDw%2Fuploads%2FUa1eRiHHwhMkj7ohHRRM%2Fconditional-text--show-if-modal.jpg?alt=media)

### Show a whole block only for some answers

Any block inside a Confirmation or an InfoBlock, and any block in an email or PDF template, can have its own condition: a paragraph, a heading, an image, a table, a group with many blocks inside.

1. Select the block.
2. In the sidebar, open **Show if** and click **Add condition**.
3. Set the condition in **Show this block only if…** and click **Save condition**.

In the editor the block gets a dashed outline and a badge, for example **Shown if Choose one is "A repair"**. The sidebar repeats the condition. Use **Edit condition** to change it, or **Always show** to remove it.

![A paragraph with a Show if condition: dashed outline and badge on the canvas, the condition in the sidebar](https://97821998-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FM2yV1foUgoGHBC66VBDw%2Fuploads%2FBn8k15yjM2Veh9dUlzq6%2Fconditional-text--block-show-if.jpg?alt=media)

The condition only applies inside a Confirmation, an InfoBlock or a template. If you move the block somewhere else in the form, it keeps its condition but is always shown.

### Fallback values

Add `|` and a text after a tag's name. The text is used when the tag is empty or missing:

```
Hi {{email.first_name|there}},
Your reference: #{{submission.id|pending}}
Price from {{meta.price|10}} EUR
```

* Quotes are optional. Use them to keep spaces at the start or end: `{{user.display_name|" friend"}}`.
* A tag without a fallback shows nothing when it's empty, as before.
* `||` inside a condition means "or". It's never read as a fallback.

### Tips

* **Emails and empty lines.** In an email or PDF, a paragraph whose whole text sits in a condition that doesn't match stays as an empty paragraph, which can leave a gap. To hide the whole paragraph, give the block a **Show if** condition instead. In the Confirmation, empty paragraphs and headings are removed for you.
* **InfoBlocks update live.** In an InfoBlock the conditions are checked again each time the visitor changes an answer, so the text changes as they fill in the form.
* **Multi-step forms.** Fields on steps the visitor skipped have no answer. `service == 'repair'` is then false, but `service != 'repair'` is true, so write the condition for the answer you expect. See [Multi-step Forms](/documentation/form-building/create-form/multi-step-forms.md).
* **Test it.** Send the form once for each case (for example once per service) to check that the right text shows.
* All tags and namespaces are listed in [Dynamic Tags and Variables](/documentation/form-building/create-form/dynamic-tags-and-variables.md).
