ejoubaud
ejoubaud

Reputation: 5241

Typoscript condition for empty variable

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 ?

Upvotes: 4

Views: 13141

Answers (4)

UnpassableWizard
UnpassableWizard

Reputation: 1279

I found for instance with a cookie, you can set no value and it will see it a empty?

[globalVar = _COOKIE|user_test_score = ]

So maybe also:

[globalVar = GP:view = ]

Not sure if it is intended but works for cookies anyway.

Upvotes: 0

mallo
mallo

Reputation: 96

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]

Upvotes: 2

Shufla
Shufla

Reputation: 872

Here is an example with "if":

1 = TEXT
1 {
    value = Absent
    override = Present
    override.if {
        isTrue.data = GP:print
    }
}

Upvotes: 10

zwen
zwen

Reputation: 74

At first there is no != in typoscript. You can only use >, <, = for conditions.

For your needs you can use this:

[globalVar = GP:view = print]

[end]

Just define a Variable "view" which can become the value "print".

  • You can also work with "if" and "override", "ifEmpty" and "required".
  • Here are some other examples of conditions in typoscript: http://www.pi-phi.de/19.html

Upvotes: 0

Related Questions