---
title: "Using else and else-if conditions"
description: "Use else and else-if conditions in templates to display different content based on varying data values. It covers how to provide alternative or fallback text when initial conditions are not met."
canonical_url: "https://resources.docmosis.com/template-tutorials/else-and-else-if"
last_reviewed: 2026-06-12
---

# Using else and else-if conditions

Within a Conditional Section it is possible to include an Else statement to allow alternative content to be provided in case where an expression is false.
Else-If style statements provide an alternative expression to be evaluated to conditionally include other content.

### Else statements

These may be used once within a <<cs_ conditional section and provide an alternative option if the condition is not true.
<<cs_trees>>option 1<<else>>option 2<<es_>> is like saying:
IF trees= "true" THEN
display all text from <<cs_trees>> up to <<else>>
OTHERWISE
display all text from <<else>> up to <<es_>>
The data would have: "trees":"true" to display option 1, and "trees":"false", or simply omit "trees", to display option 2 (JSON example).

### Else-If statements

An Else statement may also contain an expression making it an Else-If statement.
This allows an alternative condition to be tested if the first condition is not true.
If neither the <<cs_ expression nor the <<else_ expression is true, no output will appear for this section in the final document.

### Combining Else-If and Else statements

In the example template, the expression {instruments>8} will be evaluated.
If "true" then all following text up to the next <<else_ will appear in the final document.
Otherwise, the expression {instruments>3} will be evaluated.
If this expression is "true" then all the following text up to the next <<else will appear.
If both expressions evaluate to "false" then the text from <<else to <<es_ will appear.
The data would have: "instruments":"2" (JSON example).

## Using else and else-if conditions - related json data

```json
{
"trees": "true",
"topping": "fudge",
"instruments": 2
}
```

## Using else and else-if conditions - example template syntax

**ELSE**

<<cs_trees>>

There are trees in the area.

<<else>>

There are no trees in the area.

<<es_>>


**ELSE-IF**

<<cs_{topping=‘chocolate’}>>

Today’s topping is chocolate.

<<else_{topping=‘fudge’}>>

Today’s topping is fudge.

<<es_>>


**ELSE-IF and ELSE**

<<cs_{instruments>8}>>

The school band has more than eight instruments

<<else_{instruments>3}>>

The school band has more than three but less than eight instruments.

<<else>>

The school band has three or less instruments.

<<es_>>