# Writing Conditional Statements

Text templates can conditionally produce text for input to a brick.

### Condition Expression

If there are only 1 or 2 simple cases, you can write the condition inline as an expression:

```jinja
{{ "Meow" if @animal == "cat" else "Woof!" }}
```

### Using Text Templates for Brick Conditions

There are two ways to conditionally run a brick:

* Single Brick: use the Advanced > Condition configuration field
* Multiple Bricks: use the [If-Else brick](https://www.pixiebrix.com/marketplace/22b9a496-a13b-493b-bee6-8c97080d8cd2/if-else/)

The condition can be a variable, or a text expression evaluating to `true`, `t`, `yes`, `y`, `on`, or `1`.&#x20;

For example:

```jinja
{{ true if @count > 0 }}
```

```jinja
{{ true if not @myVariable }}
```

### Comparison and Logic Expressions

PixieBrix text templates support comparison and logical operators in expressions:

* `==` , `!=`: equals and not equals
* `>`, `<`, `>=`, `<=`: numeric comparison
* `and` , `or`: logic
* `not`: negation

Here’s an example showing comparison and logic in an expression:

{% hint style="warning" %}
To provide multiple conditions using `and` or `or`, provide them within the same template expression&#x20;
{% endhint %}

```jinja
{{ true if @run > 0 and @animal == "cat" }}
```

### Condition Tag Blocks

If there are multiple cases, or one or more cases are multi-line, you can use condition blocks to provide the cases:

```jinja
{% if @animal == "cat" %}
  Meow!
{% elif @animal == "dog" %}
  Woof!
{% else %}
  ???
{% endif %}
```

As you can see, blocks are designated using `{%` and `%}` instead of the `{{` mustache braces. The tags are `if`, `elif`, and `endif`.

{% hint style="warning" %}
Note that alternative cases use the `elif` tag with no space. I.e., as opposed to `else if` which is used in many programming languages\
\
✅  `elif` \
❌  `else if`<br>
{% endhint %}

You can learn more about the `if` [tag in the Nunjucks Template Language documentation](https://mozilla.github.io/nunjucks/templating.html#if).
