Typoscript condition for empty variable
12,235
Solution 1
Here is an example with "if":
1 = TEXT
1 {
value = Absent
override = Present
override.if {
isTrue.data = GP:print
}
}
Solution 2
With globalString it's also possible to use a Regular Expression as comparison. Depending on the context this might also be a viable solution.
[globalString = GP:test = /.+/]
# This is only evaluated if GP:test contains one or more characters
[global]
Related videos on Youtube
Author by
ejoubaud
Dev, data freak, travel addict, climber. Empiricist and minimalist, at least when it comes to software: As much as I love elegant code, I love simple solutions even more. Same for powerful vs focused apps. And well-thought-out vs well-tested ideas.
Updated on October 17, 2022Comments
-
ejoubaud over 1 year
Is there a way to use Typoscript condition to assign a different value to a TypoScript TEXT if a GET variable is empty ?
Something like that :
xxxx.1 = TEXT [globalVar = GP:print != ""] xxxx.1.value = Absent [else] xxxx.1.value = Present [end]
Of course here the
!= ""
doesn't work, so what should I use instead ? -
Micromega over 11 yearsBut is this is a condition? It looks like a complicated default value?
-
Shufla over 11 yearsThat is not a condition. Also note that this will be cached. A condition could be [globalVar = GP:print = 1]. So your link would have to append "?print=1".
-
Александр Фишер over 9 years@Phpdna This looks like a complicated default value but afaik its the only way I could check if a GET-param is set. Note, that if "?print=0" will be evaluated as false and the value "Absent" will be used in this example.