---
title: if
description: "Render content when a condition is true."
---

# if

Render content when a condition is true.

## Syntax

```knap
{% if condition %}...{% elseif other %}...{% else %}...{% endif %}
```

## Usage

- The first condition that is true decides which content is shown.
- Add `elseif` to check another condition, or `else` for content to show when all conditions are false. Both are optional.
- Close the block with `endif`.

## True and false

- Conditions treat `false`, `null`, `undefined`, an empty string, `0`, and an empty array as false. Other values are treated as true.

## Example

```json title="Data"
{
  "published": false,
  "draft": true
}
```

```knap title="Template"
{% if published %}Published{% elseif draft %}Draft{% else %}Archived{% endif %}
```

```md title="Output"
Draft
```

## Related

- [`for`](/logic/for). Repeat content for each item in an array.
