Startseite > Template- und Themeprogrammierung > Skriptsprache > Truthy and falsy

Truthy and falsy

Alles was in Vergleichen den Wert true zurück gibt, wird truthy genannt. Alles was in Vergleichen den Wert false zurück gibt, wird falsy genannt. Alle Typen von Objekte können entweder truthy oder falsy sein.

Truthy

In Liquid sind alle Werte truthy. Ausnahme bilden null und false.

<liquid-input>
{% assign name = 'Otto' %}
{% if name %}
  This condition is true.
{% endif %}

{% assign name = '' %}
{% if name %}
  This condition is true.
{% endif %}

{% if shop.description %}
  This condition is true, even when shop.description is empty.
{% endif %}
</liquid-input>

<liquid-output>
This condition is true.
This condition is true.
This condition is true, even when shop.description is empty.
</liquid-output>

Falsy

In Liquid sind Objekte die die Werte null und false haben immer falsy.

<liquid-input>
{% assign name = false %}
{% if name %}
  This condition is true.
{% else %}
  This condition is false.
{% endif %}

{% assign name = null %}
{% if name %}
  This condition is true.
{% else %}
  This condition is false.
{% endif %}
</liquid-input>

<liquid-output>
This condition is false.
This condition is false.
</liquid-output>