mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 02:40:41 -07:00
Mention usage of empty and EmptyDrop
This commit is contained in:
+30
-1
@@ -3,13 +3,14 @@ title: Types
|
|||||||
description: An overview of data types in the Liquid template language.
|
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)
|
- [String](#string)
|
||||||
- [Number](#number)
|
- [Number](#number)
|
||||||
- [Boolean](#boolean)
|
- [Boolean](#boolean)
|
||||||
- [Nil](#nil)
|
- [Nil](#nil)
|
||||||
- [Array](#array)
|
- [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.
|
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 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.
|
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`.
|
||||||
|
|||||||
Reference in New Issue
Block a user