first

The first filter returns the first element of an array, hash or string.

Array

{{ [1, 2, 3, 4]|first }}

The above will output: 1.

Hash

{{ {'name': 'Sam', 'age': 55}|first }}

String

{{ 'Bob Hope'|first }}

The above will output "B"

Assignment

As with all filters, you can use the first filter when assigning a variable.

{% set name = 'Bob Hope' %}
{% set letter = name|first %}

< Back to the list of filters