Mention usage of empty and EmptyDrop

This commit is contained in:
EricFromCanada
2021-02-22 17:15:17 -05:00
parent 1b53edf052
commit fb8432ca16

View File

@@ -3,13 +3,14 @@ title: Types
description: An overview of data types in the Liquid template language.
---
Liquid objects can have one of five types:
Liquid objects can be one of six types:
- [String](#string)
- [Number](#number)
- [Boolean](#boolean)
- [Nil](#nil)
- [Array](#array)
- [EmptyDrop](#emptydrop)
You can initialize Liquid variables with the [assign]({{ "/tags/variable/#assign" | prepend: site.baseurl }}) or [capture]({{ "/tags/variable/#capture" | prepend: site.baseurl }}) tags.
@@ -124,3 +125,31 @@ Adam
You cannot initialize arrays using only Liquid.
You can, however, use the [split]({{ "/filters/split/" | prepend: site.baseurl }}) filter to break a string into an array of substrings.
## EmptyDrop
An EmptyDrop object is returned if you try to access a deleted object. In the example below, `page_1`, `page_2` and `page_3` are all EmptyDrop objects:
```liquid
{% raw %}
{% assign variable = "hello" %}
{% assign page_1 = pages[variable] %}
{% assign page_2 = pages["does-not-exist"] %}
{% assign page_3 = pages.this-handle-does-not-exist %}
{% endraw %}
```
### Checking for emptiness
You can check to see if an object exists or not before you access any of its attributes.
```liquid
{% raw %}
{% unless pages == empty %}
<h1>{{ pages.frontpage.title }}</h1>
<div>{{ pages.frontpage.content }}</div>
{% endunless %}
{% endraw %}
```
Both empty strings and empty arrays will return `true` if checked for equivalence with `empty`.