开发者

Is it possible to compare variables in TypoScript?

Is it possible to compare variables in 开发者_如何学运维TypoScript? If it is possible - then how?


I struggled with the very same issue, so here is what I found out. I was trying to include a plugin, but only if a certain TypoScript configuration variable was already set, which isn't possible using TypoScript conditions, because these don't have access to TypoScript variables!

So the way to go really is the ominous if-function. The documentation says the following:

This function returns true if ALL of the present conditions are met (they are AND'ed). If a single condition is false, the value returned is false.

What they do not mention is, that, if the if-function returns false, the Element in question is just not displayed/executed or whatever TypoScript actually does, for example:

10 = TEXT
10.value = foobar
10.if.value = 42
10.if.equals = 24

This TEXT-element would never be displayed, because the condition does not evaluate to true. The following however, would be displayed:

10 = TEXT
10.value = foobar
10.if.value = 42
10.if.isGreaterThan = 24

if.value always holds the value you are comparing to, and then there are a bunch of property you may use to compare another value to it.

The only good example in the documentation is this one:

This is a GIFBUILDER object that will write "NEW" on a menu-item if the field "newUntil" has a date less than the current date!

...
30 = TEXT
30.text = NEW!
30.offset = 10,10
30.if {
    value.data = date: U
    isLessThan.field = newUntil
    negate = 1
}
...

But beware... these properties are not available on any element type (USER_INT for example, does not have them).

What I did to workaround that problem was to wrap the USER_INT in a COA as follows:

config.enableMyStuff = 1
page.20 = COA
page.20 {
    10 =< plugin.tx_myextension_pi1
    if.value < config.enableMyStuff
    if.equals = 1
}


You can compare variables by using the equals-keyword. If you typoscript is

10.value = 10

then you can assign a

10.equals = 10

and a condition

10.iftrue = 20

I'm sorry it's from my memory but you can read it in the typoscript manual. I want to say it's a recursive data structure using an adjacent tree model. Here is a link: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.5.0/view/1/5/#id2621713


It's possible with a normal TypoScript "globalString" condition and a constant:

[globalString = LIT:foobar = {$some.typoscript.constant}]
    ...
[global]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜