# if

> Render content only when a condition holds.

`if` renders its content only when a condition is true. Add `elseif` and `else` for other cases.

page.kiln:

```kiln
{% if page.hero %}
	<div class="hero">{{ page.hero }}</div>
{% elseif page.image %}
	<img src="{{ page.image }}" alt="">
{% else %}
	<hr>
{% endif %}
```

Output:

```html
<img src="/img/cover.jpg" alt="">
```

## Conditions

Conditions follow Kiln's [rules for true and false](https://kilnlang.com/docs/language/values/#true-and-false). Empty arrays and hashes are false, and `"0"` is true.

Combine conditions with `and`, `or` and `not`, and use tests with `is`:

```kiln
{% if user and not user.banned %}
{% if posts is not empty %}
{% if page.subtitle is defined %}
```

## Inline conditions

For a value rather than a block of markup, use `? :` inside an expression:

page.kiln:

```kiln
<a class="{{ active ? "link link--active" : "link" }}">Home</a>
```

Output:

```html
<a class="link link--active">Home</a>
```

`if` doesn't create a scope, so variables set inside it are still there afterwards.
