
To search a string part (needle) in string (haystack), you can easily use the PHP strpos function. But this function doesn’t exist in TypoScript.
The following TypoScript return true if the needle is found in the haystack. This can be used in an if condition.
cObject = COA
cObject {
1 = LOAD_REGISTER
1 {
# search for http (or https).
needle = http
# search in
haystack.field = header_link
# split haystack by the needle
# result is a haystack without a needle, if found
findNeedleInHaystack.cObject = TEXT
findNeedleInHaystack.cObject {
data = REGISTER:haystack
split.token.data = REGISTER:needle
}
}
# compare REGISTER:haystack and result of REGISTER:findNeedleInHaystack
# if both are the same, nothing was found
10 = TEXT
10 {
# true will be returned, if the needle was found inside haystack
value = true
if {
value.data = REGISTER:haystack
equals.data = REGISTER:findNeedleInHaystack
# if the same, then negate the return value
negate = 1
}
}
}
The above COA will return true if http is found in the header_link field. I used this to add ATagParams for external link, in assumption that link with http(s) is an external link.
ATagParams = class="external"
ATagParams.if {
cObject = COA
cObject {
// the strpos function
}
}