{lookup:value:values:delimiter:text}

Description

Finds value in a delimited list and returns the matched item position. With no text parameter it returns the 1-based position (_#pos). The list is split on delimiter (a hyphen by default), or parsed as a JSON array when values starts with an open square bracket and ends with a close square bracket. Inside text you may use the placeholders _#pos (1-based position), _#key (0-based position) and _#count (the number of values). Returns an empty string when values is empty or when value is not in the list. The comparison is not case-insensitive and parameters are not trimmed, so a leading or trailing space is significant. This command is not cached (it is re-evaluated on every render).

Parameters

value required

The value to search for in the list. The match is exact (not case-insensitive) and the value is not trimmed.

values required

The delimited list to search. It is split on the delimiter, or parsed as a JSON array when it starts with an open square bracket and ends with a close square bracket. When empty, lookup returns an empty string.

delimiter optional default -

Character or string that separates the values. When omitted, a hyphen is used (or JSON parsing when values looks like a JSON array). It may contain spaces - parameters are not trimmed.

text optional default _#pos

Template for the result. Use the placeholders _#pos (1-based position), _#key (0-based position) and _#count (the total number of values). When omitted, the 1-based position is returned.

Examples

test{lookup:10:5-8-10-12-15}
Expected3
Actual3
With no text parameter, lookup returns the 1-based position of the value. Here 10 is the third item, so the result is 3.
test{lookup:30:10-20-30:-:found at position _#pos (index _#key)}
Expectedfound at position 3 (index 2)
Actualfound at position 3 (index 2)
All three placeholders may appear in the text. 30 is the third of three values, so position is 3 and index is 2.
test{lookup:cz:en;cz;sk:;}
Expected2
Actual2
When the list is not hyphen-separated, pass the separator as the third parameter. Here a semicolon splits the list, and cz is the second item.
test[{lookup:x:}]
Expected[]
Actual[]
An empty values list also yields an empty string, before any search happens. The square brackets are literal text added to make the empty result visible.
test{lookup:blue:["red","green","blue"]}
Expected3
Actual3
When values starts with an open square bracket and ends with a close square bracket it is parsed as a JSON array, so the delimiter is not needed. blue is the third element.
test{lookup:banana:apple-banana-cherry}
Expected2
Actual2
The list can hold any strings, not just numbers. banana is the second item, so the result is 2.
test{lookup:10:5-8-10-12-15:-:_#pos of _#count}
Expected3 of 5
Actual3 of 5
The text parameter is a template. _#pos is the 1-based position and _#count is the number of values in the list.
test{lookup:cherry:apple-banana-cherry:-:_#key}
Expected2
Actual2
_#key is the 0-based index, one less than _#pos. cherry is the third item, so _#key is 2. The third parameter (-) is the explicit default hyphen delimiter.
test[{lookup:99:5-8-10-12-15}]
Expected[]
Actual[]
When the value is not present, lookup returns an empty string. The square brackets here are literal text in the example, added only to make the empty result visible.