{ifeqfield:item_id:field:var:text:else_text}

Description

Compares a value against every value held by one field of an item, and prints one of two texts depending on whether any of them match. If the field is multivalue (a listbox, checkbox group, or any field that can hold several values), ifeqfield matches when at least one of those values equals var; for a single-value field it is a plain equality test. The first parameter is the item to read. Leave it empty (or pass current) to read the item currently being displayed. If the item does not exist, or the field is not present on it, the else_text branch is printed. Inside text or else_text the alias _#1 stands for var (the value you searched for) and is substituted in whichever branch is returned. The comparison is exact and case-sensitive. Unlike if, which compares numbers, ifeqfield compares the field values as strings.

Parameters

item_id optional default (empty = current item)

The item to read the field from (a 32-character long id). Leave empty, or pass the literal current, to use the item currently being displayed.

field optional default (empty)

The field id (or its _#ALIAS) whose values are tested, for example abstract........ or category.......1. If the item does not have this field, else_text is printed.

var optional default (empty)

The value to look for. ifeqfield prints text when at least one value of the field equals var exactly (case-sensitive), otherwise else_text. The alias _#1 in either branch is replaced with this value.

text optional default (empty)

Printed when the field contains var. May contain any AA expression and the alias _#1 (which expands to var).

else_text optional default (empty)

Printed when the field does not contain var, or when the item or field is missing. May contain any AA expression and the alias _#1 (which still expands to var).

Examples

test{ifeqfield:5726c2c6b035d7aab450d1794e9e90d7:abstract........:red:matched:not matched}
Expectedmatched
Actualmatched
Read field abstract........ of the fixture item; its value is red, so var red matches and the text branch is printed.
test{ifeqfield:5726c2c6b035d7aab450d1794e9e90d7:abstract........:green:matched:not matched}
Expectednot matched
Actualnot matched
The field holds red, not green, so the else_text branch is printed.
test{ifeqfield:5726c2c6b035d7aab450d1794e9e90d7:abstract........:red:value is _#1:none}
Expectedvalue is red
Actualvalue is red
The alias _#1 in the returned branch expands to var (the value you searched for).
test{ifeqfield:5726c2c6b035d7aab450d1794e9e90d7:integer.........:100:Y:N}
ExpectedY
ActualY
ifeqfield compares values as strings; the fixture integer field holds 100, so 100 matches. Use if for numeric range comparisons.
test{ifeqfield:5726c2c6b035d7aab450d1794e9e90d7:nosuchfield....:red:Y:N}
ExpectedN
ActualN
When the field is not present on the item, the else_text branch is printed.
test{ifeqfield:00000000000000000000000000000000:abstract........:red:Y:N}
ExpectedN
ActualN
An empty, invalid, or non-existent item id yields the else_text branch.
virtual{ifeqfield::category........:news:in news: not in news}
Expected( not in news)
Actual not in news
Leaving the first parameter empty reads the item currently being displayed, so the result depends on that item. On this reference page the current item is this example row, which has no category........ value, so it prints the else branch.
testclass="{ifeqfield:5726c2c6b035d7aab450d1794e9e90d7:abstract........:red:is-red:is-other}"
Expectedclass="is-red"
Actualclass="is-red"
The common real-world use: emit a CSS class (or any attribute) that depends on a field value. Leave the else branch empty to emit nothing when there is no match.