mirror of
https://github.com/kemko/liquid.git
synced 2026-01-04 17:25:41 +03:00
852 B
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 %}