Files
liquid/_filters/first.md
2019-09-11 10:46:41 -04:00

852 B

title, description
title description
first Liquid filter that returns the first item of an array.

Returns the first item of an array.

Input

```liquid {% raw %} {{ "Ground control to Major Tom." | split: " " | first }} {% endraw %} ```

Output

```text {{ "Ground control to Major Tom." | split: " " | first }} ```

Input

```liquid {% raw %} {% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}

{{ my_array.first }} {% endraw %}


<p class="code-label">Output</p>
```text
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}

{{ my_array.first }}

You can use first with dot notation when you need to use the filter inside a tag:

{% raw %}
{% if my_array.first == "zebra" %}
  Here comes a zebra!
{% endif %}
{% endraw %}