
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
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.
1 2 3 4 5 6 7 |
ATagParams = class="external" ATagParams.if { cObject = COA cObject { // the strpos function } } |