{ifin:haystack:needle:text:else_text}

Description

Prints text when haystack contains needle as a substring, otherwise prints else_text. The test is a plain case-sensitive substring match (haystack contains needle), not equality and not word matching. You may pass several needle:text pairs after the haystack - they are tested left to right and the FIRST matching pair wins; any single leftover parameter at the end is the else_text used when nothing matched. Two placeholders are available inside the chosen text: _#1 expands to the whole haystack and _#2 expands to the needle that matched. Two edge cases to know: an empty needle ALWAYS matches (it short-circuits to its text), and parameters are NOT trimmed, so leading or trailing spaces in haystack or needle are significant. This command is never cached. For set membership use ifintersect; for exact equality use ifeq.

Parameters

haystack required default (none - required)

The string searched for the needle. The match succeeds when this string contains the needle as a substring (case-sensitive). Not trimmed: leading and trailing spaces count.

needle required default (none - required)

The substring to look for inside the haystack. An empty needle always matches. You can repeat needle and text as further pairs (needle2 text2 ...); the first matching needle wins.

text optional default (empty string)

Printed when the needle is found. May contain b5c7fde662997a561583ff362f86f67a-bbd734ec6b26e958511dbeee6984d0c7-048a1a16331d641d402211a8fe5702ef-a2cdcc6dde926f1dcf8f35e7b9864725 (the whole haystack) and (the needle that matched). In a multi-pair call each needle has its own text.

else_text optional default (empty string)

Printed when no needle matched. It is the single leftover parameter after all needle:text pairs. b5c7fde662997a561583ff362f86f67a-bbd734ec6b26e958511dbeee6984d0c7-048a1a16331d641d402211a8fe5702ef-a2cdcc6dde926f1dcf8f35e7b9864725 expands to the haystack here too ( is empty since nothing matched). Omit it to print nothing on no match.

Examples

test{ifin:ActionApps CMS:CMS:yes:no}
Expectedyes
Actualyes
Haystack 'ActionApps CMS' contains 'CMS', so the text 'yes' is printed.
test{ifin:ActionApps CMS:Drupal:yes:no}
Expectedno
Actualno
The haystack does not contain 'Drupal', so the else_text 'no' is printed.
test[{ifin:hello world:xyz:found}]
Expected[]
Actual[]
With no needle matched and no else_text given, the result is the empty string (shown here between brackets).
test{ifin:ActionApps:apps:lower:Apps:capital A:none}
Expectedcapital A
Actualcapital A
Lowercase 'apps' is not found in 'ActionApps' (it has a capital A), so the first pair fails; the second needle 'Apps' matches and prints 'capital A'.
test{ifin:de,ru,cz,pl,en:cz:Found code _#2:not found}
ExpectedFound code cz
ActualFound code cz
When 'cz' is found, _#2 in the text expands to the needle that matched.
test{ifin:premium-plan:premium:_#1 is active:none}
Expectedpremium-plan is active
Actualpremium-plan is active
_#1 expands to the entire haystack inside the chosen text.
test{ifin:de,ru,cz,pl,en:en:English:cz:Czech:Unknown language}
ExpectedEnglish
ActualEnglish
Pairs are tested left to right. 'en' is found first, so 'English' wins even though 'cz' would also match.
test{ifin:de,ru,cz,pl,en:fr:French:es:Spanish:Unknown language}
ExpectedUnknown language
ActualUnknown language
Neither 'fr' nor 'es' is found, so the trailing else_text 'Unknown language' is used.
test{ifin:anything::matched:fallback}
Expectedmatched
Actualmatched
A needle that is empty short-circuits to its text. Here the empty needle (between the two colons) matches immediately and prints 'matched', never reaching the fallback. Avoid feeding an empty value as the needle.
test{ifin:one two three:two :matched:no}
Expectedmatched
Actualmatched
Parameters are not trimmed. The needle 'two ' (with a trailing space) is found in 'one two three' because 'two three' contains 'two '. A trailing space in the needle is part of what is searched.
virtual{ifin:{qss:lang}:cz: checked}
Expected( checked when the lang query parameter contains cz, otherwise empty)
A common filter-form idiom. {qss#:lang} reads the current 'lang' query-string value; if it contains 'cz', the attribute ' checked' is emitted so the matching checkbox stays ticked after submit. Runtime-dependent, so shown as an illustration.