{constant:group_id:value:what:value_delimiter:output_delimiter}

Description

Looks up one constant in a constant group by its value and returns a chosen property of it - by default the constant name (its human-readable label). Constant groups are the shared lookup tables behind category and select fields; a stored field usually holds the constant value (a code like 2), and this expression turns that code into the label readers see. The first parameter is the group id, the second is the value to find. The optional third parameter what selects which property to return: name, value, short_id, description, pri, group, class, id or level - or any AA expression built from the constant aliases _#NAME###_, _#VALUE##_, _#DESCRIPT, _#PRIORITY and the rest. If you pass a value_delimiter (fourth parameter), the value is split on it and each part is looked up in turn, so one call can translate a whole multi-value field at once; the results are joined by output_delimiter (fifth parameter, default a comma and a space). A value that is not in the group returns an empty string. Use the singular constant for one lookup; use constants (plural) to list every entry in a group.

Parameters

group_id required

The constant group id (its 5-16 character identifier). Identifies which lookup table to search. Required.

value required

The value to find inside the group - usually the code stored in a content field. With value_delimiter set, this is a delimited list of values to translate at once. Required.

what optional default name

Which constant property to return: name, value, short_id, description, pri, group, class, id or level. May instead be any AA expression using the constant aliases (_#NAME###_, _#VALUE##_, _#DESCRIPT, _#PRIORITY, etc.), letting you build custom output per matched constant.

value_delimiter optional

If set, value is split on this delimiter and each part is looked up separately - used to translate a whole multi-value field in one call. Empty means a single lookup.

output_delimiter optional default ,

Joins the results when translating multiple values. Only used when value_delimiter is set.

Examples

test{constant:expr_status:2}
ExpectedPublished
ActualPublished
The simplest use: turn a stored code into its label. With no third parameter, what defaults to name, so value 2 in the expr_status group returns Published.
test{constant:expr_status:2:description}
ExpectedVisible to the public
ActualVisible to the public
Pass a third parameter to return a different property. Here description gives the longer text stored on the constant instead of its short name.
test[{constant:expr_status:9}]
Expected[]
Actual[]
A value that is not in the group returns an empty string. The square brackets are only here to make the empty result visible; expr_status has no constant with value 9.
test{constant:expr_status:1-3:name:-:, }
ExpectedDraft, Archived
ActualDraft, Archived
With a value_delimiter (the fourth parameter, here a dash) the value is split and each part looked up. The results are joined by output_delimiter (fifth parameter, here a comma and a space). This translates a whole multi-value field in one call.
test{constant:expr_status:1-2-3:_#NAME###_:-: | }
ExpectedDraft | Published | Archived
ActualDraft | Published | Archived
The what parameter can be an AA expression using constant aliases. Here _#NAME###_ is the constant name; combined with a value_delimiter it renders each matched constant through the template and joins them with the chosen output delimiter.
test{constant:expr_status:2:_#VALUE##_ = _#NAME###_}
Expected2 = Published
Actual2 = Published
When what is not one of the known property keywords it is treated as an AA expression and expanded against the matched constant. _#VALUE##_ and _#NAME###_ are replaced with that constant value and name.