---
title: '|yesno'
description: maps `True`, `False`, and `None` to mapped values.
date: '2026-08-02'
categories:
  - Filter
  - Logic
canonical: https://www.djangotemplatetagsandfilters.com/filters/yesno/
doc_link: https://docs.djangoproject.com/en/6.0/ref/templates/builtins/#yesno
---

# |yesno

maps `True`, `False`, and `None` to mapped values.

## Documentation

The `yesno` filter maps values that evaluate to `True`, `False`, and `None` to "yes", "no", and "maybe" or to alternative strings passed in as a comma-delimited string.

### Variable

```django
inventory = {
    'gloves': 0,
    'hats': 51,
    'scarves': 2,
    'socks': 13
}
```

### Template

```django
<ol>
{% for item, remaining in inventory.items %}
  <li class="{{ remaining|yesno:'instock,outofstock' }}">
    {{ item }}: {{ remaining }} remaining
    {{ remaining|yesno:',(time to place an order)' }}
  </li>
{% endfor %}
</ol>
```

Notice how the `yesno` filter is used once to determine the `class` value and again to determine whether or not to output “(time to place an order)”.

### Result

```django
<ol>
<li class="outofstock">gloves: 0 remaining (time to place an order)</li>
<li class="instock">hats: 51 remaining</li>
<li class="instock">scarves: 2 remaining</li>
<li class="instock">socks: 13 remaining</li>
</ol>
```

## Commentary

This is particularly useful for selecting class names for HTML elements.
