{ifeq:etalon:option1:text1:...:else_text}

Description

Compares one value against one or more options and returns the text of the first option that matches. ifeq trims the etalon and each option, then tests them with strict, case-sensitive string equality. The first matching option/text pair wins and its text is returned; if nothing matches, the optional trailing argument (else_text) is returned, or an empty string when that argument is omitted. With several option/text pairs ifeq works like a compact switch. Inside the returned text the alias _#1 is replaced by the compared value (etalon) and _#2 by the first option, and any other AA expression is expanded as usual. Use ifeq for plain equality (marking the active navigation item, branching on a language or status code); for numeric comparisons such as greater-than or less-than use the if command instead, and to test a multi-value field against a value use ifeqfield. ifeq is never cached, so it always reflects the current request.

Parameters

etalon required

The value to test. It is trimmed before comparison, then matched against each option with strict (case-sensitive) string equality.

option1 required

The first value to compare against etalon. Each option is also trimmed before comparison. Pair it with text1.

text1 required

The text returned when etalon equals option1. Inside it, _#1 is replaced by etalon and _#2 by option1; you may also use any other AA expression.

option2, text2, ... optional

Optional further option/text pairs. ifeq tests them in order and returns the text of the first option that equals etalon - it behaves like a small switch.

else_text optional default (empty string)

Optional trailing argument returned when no option matches. If omitted, a non-match returns an empty string.

Examples

test{ifeq:hello:hello:Match found:No match}
ExpectedMatch found
ActualMatch found
When etalon equals an option, ifeq returns that options text.
test{ifeq:cat:dog:Woof:Not a dog}
ExpectedNot a dog
ActualNot a dog
The last unpaired argument is the else text, returned when no option matches.
test[{ifeq:cat:dog:Woof}]
Expected[]
Actual[]
With no else argument, a non-match returns an empty string. Brackets here make the empty result visible.
test{ifeq:cz:en:English:cz:Czech:Unknown}
ExpectedCzech
ActualCzech
ifeq accepts any number of option/text pairs and returns the first match - like a small switch. The trailing argument is the fallback.
test{ifeq:apple:apple:You picked _#1:none}
ExpectedYou picked apple
ActualYou picked apple
Inside the returned text, _#1 is replaced by the compared value (etalon) and _#2 by the first option.
virtual<a href="/about" {ifeq:{xseo}:about:class="active"}>About</a>
Expected(when the URL segment is about: About)
About)">ActualAbout
Common navigation pattern: compare the current URL segment {xseo} to a page key and emit class="active" on the matching link. Output depends on the request URL.