# Fallback filter

**URL:** <https://talk.jekyllrb.com/t/fallback-filter/1054>\
**Category:** Help\
**Created:** [October 5, 2017, 1:55pm UTC](https://talk.jekyllrb.com/t/fallback-filter/1054 "2017-10-05T13:55:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcnesium](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mcnesium/32/512_2.png) [@mcnesium](https://talk.jekyllrb.com/u/mcnesium)\
**Post date:** [October 5, 2017, 1:55pm UTC](https://talk.jekyllrb.com/t/fallback-filter/1054/1 "2017-10-05T13:55:40Z")

</div>

I wonder if with Jekyll 3.6 it is still necessary to for example do

```
controls: {% if site.controls != null %}{{ site.controls }}{% else %}true{% endif %}

```

instead of the much cleaner

```
controls: {{ site.controls | fallback: true }}

```

that has been offered in [this PR](https://github.com/jekyll/jekyll/pull/1822) but obviously never included but then sadly `frozen-due-to-age`. Is there any chance to get to see this functionality in Jekyll anytime soon? Is there a reason why this has not been integrated yet? Is there another way to get rid of this messy if-then-else glob?

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [October 5, 2017, 7:53pm UTC](https://talk.jekyllrb.com/t/fallback-filter/1054/2 "2017-10-05T19:53:39Z")

</div>

I have no idea what the `fallback` filter is, but Liquid has a `default` filter that works how you want. Replace `fallback` with `default` and you should be good to go.

```auto
controls: {{ site.controls | default: true }}

```

> **[default](https://shopify.github.io/liquid/filters/default/)**
>
> Liquid filter that specifies a fallback in case a value doesn't exist.

---

<div class="post-metadata">

**Author:** ![mcnesium](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mcnesium/32/512_2.png) [@mcnesium](https://talk.jekyllrb.com/u/mcnesium)\
**Post date:** [October 6, 2017, 8:12am UTC](https://talk.jekyllrb.com/t/fallback-filter/1054/3 "2017-10-06T08:12:01Z")

</div>

Thank you for the suggestion. I actually did try this in the first place, but did not get it to work as expected:

| file | content |
| --- | --- |
| `_config.yml` | `controls: false` |
| `default.tmpl` | `controls: {{ site.controls | default: true }}` |
| `index.html` | `controls: true` |
| but: | |
| `_config.yml` | `controls: false` |
| `default.tmpl` | `controls: {{ site.controls }}` |
| `index.html` | `controls: false` |

I have no explanation why implementing the `default` filter in the template turns out `true`, so I did some research and found the fallback PR and I figured Jekyll is doing something differently.

Do you have any clue, whats wrong with my settings?

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [October 6, 2017, 8:45am UTC](https://talk.jekyllrb.com/t/fallback-filter/1054/4 "2017-10-06T08:45:10Z")

</div>

The `default` filter seems to be working as expected, from the example you provided.

`{{ site.controls | default: true }}` means the result will _default to_ `true` when `site.controls` evaluates to a “falsey”.

In the case of Liquid (and Ruby in general), both `nil` and `false` are the only “falsey” values. Everything else is a “truthy”.

One approach then would be to adjust your template to use a `disabled` setting.

```auto
{% unless site.controls == 'disabled' %}
  // controls are enabled by default.
  // markup related to controls here
{% endunless %}
```

---

<div class="post-metadata">

**Author:** ![mcnesium](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mcnesium/32/512_2.png) [@mcnesium](https://talk.jekyllrb.com/u/mcnesium)\
**Post date:** [October 6, 2017, 10:10am UTC](https://talk.jekyllrb.com/t/fallback-filter/1054/5 "2017-10-06T10:10:10Z")

</div>

yes, that totaly makes sense. thank you for the explanation 🙂
