{index:field_id:index:item_id:lang}

Description

Returns a single value from a multi-value field of an item. Fields in AA can hold several values at once (a checkbox or relation list, several abstracts, or language translations) and index reads the value at one zero-based position. With no item id it reads the field of the item being rendered; give an item id to read any item by its long id. The optional lang code shifts the position into that language's slot, so index can fetch one specific translation of a multi-language field. A position past the last value, or a language with no translation, returns an empty string. The default position is 0, the first value.

Parameters

field_id required

The id of the field to read from, such as headline........ or abstract......... This is the only required parameter.

index optional default 0

Zero-based position of the value to return within a multi-value field. 0 is the first value, 1 the second, and so on. A position past the last stored value returns an empty string.

item_id optional default current item

Long id of the item to read. When omitted, index reads the field of the item currently being rendered (for example the current row of a view).

lang optional default current language

Two-letter language code (such as cz or en) for multi-language fields. It shifts the position into that language's slot so index returns the value stored for that translation. A language with no stored translation returns an empty string.

Examples

test[{index:abstract........:0:5726c2c6b035d7aab450d1794e9e90d7}]
Expected[red]
Actual[red]
The Short text field of the fixture item Gamma holds the single value red. Position 0 is the first value. The item id is passed as the third parameter so the example does not depend on any current item.
test[{index:abstract........::5726c2c6b035d7aab450d1794e9e90d7}]
Expected[red]
Actual[red]
Leaving the position empty defaults to 0, so this returns the same first value as writing the position 0 explicitly.
test[{index:integer.........:0:4f3362a62847fe1f8c59ba28a92d42c0}]
Expected[42]
Actual[42]
index works on any field type. Here it reads the first value of the Number field of the fixture item Beta, which is 42.
test[{index:abstract........:1:5726c2c6b035d7aab450d1794e9e90d7}]
Expected[]
Actual[]
Gamma's Short text field stores only one value, so position 1 (the second value) does not exist and index returns an empty string instead of an error.
test[{index:abstract........:-1:5726c2c6b035d7aab450d1794e9e90d7}]
Expected[]
Actual[]
Positions are zero-based and never wrap around. A negative position matches no value, so index returns an empty string.
test[{index:headline........:0:a65d19971986e750761f0efcd9a16b1b}]
Expected[Alpha]
Actual[Alpha]
Pass any item's long id as the third parameter to read that item from anywhere. This reads the Headline of the fixture item Alpha.
virtual{index:abstract........}
Expected(the current item's first Short text value)
With no item id, index reads the field of the item being rendered, for example the current row inside a view or item template. The output is whatever that item's first Short text value is, so this is illustrative rather than a fixed test.
virtual{index:keywords........:1}
Expected(the current item's second keyword)
On a field that stores several values (a checkbox or relation list, several abstracts), position 1 returns the second value, position 2 the third, and so on. The result depends on the current item's data, so this is illustrative.
virtual{index:headline........:::cz}
Expected(the Czech translation of the current Headline)
For a multi-language field, the fourth parameter selects a language slot. With the position and item id left empty, this returns the Czech translation of the current item's Headline. A common pairing is one cell {index:headline........:::cz} for Czech next to another for English. A language with no stored translation returns empty.