TSref/if

From TYPO3Wiki

Jump to: navigation, search
TSref/if
Translations info
An english page for every translation.
All pagenames in english.

  en       de   nl   fr   ja   zh  

TypoScript This page is document in progress.


if

Source: http://typo3.org/documentation/document-library/references/doc_core_tsref/current/view/5/7/

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.

The returned value may still be negated by the ".negate"-property.

Property: Data type: Description: Default:
isTrue str /stdWrap If the content is "true".... (not empty string and not zero)
isFalse str /stdWrap If the content is "false"... (empty or zero)
isPositive int /stdWrap

+ calc

returns false if content is not positive
isGreaterThan value /stdWrap returns false if content is not greater than ".value"
isLessThan value /stdWrap returns false if content is not less than ".value"
equals value /stdWrap returns false if content does not equal ".value"
isInList value /stdWrap returns false if content is not in the comma-separated list ".value".

The list in ".value" may not have spaces between elements!!

value value /stdWrap "value" (the comparison value mentioned above)
negate boolean This negates the result just before it exits. So if anything above returns true the overall returns ends up returning false!!
directReturn boolean If this property exists the true/false of this value is returned. Could be used to set true/false by TypoScript constant

[tsref:->if]

Explanation:

the "if"-function is a very odd way of returning true or false! Beware!

"if" is normally used to decide whether to render an object or return a value (see the cObjects and stdWrap)

Here is how it works:

The function returns true or false. Whether it returns true or false depends on the properties of this function. Say if you set "isTrue = 1" then result is true. If you set "isTrue.field = header" the function returns true if the field "header" in $cObj->data is set!

If you want to compare values, you must load a base-value in the ".value"-property.

#Example:
.value = 10
.isGreaterThan = 11

This would return true because the value of ".isGreaterThan" is greater than 10, which is the base-value.

More complex is this:

.value = 10
.isGreaterThan = 11
.isTrue.field = header
.negate = 1

There are two conditions - isGreaterThan and isTrue. If they are both true, the total is true (AND) BUT (!) the result if the function in total is false because the ".negate"-flag inverts the result! Example:

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
}

...

# Example:
# Querystring parameter used as condition
# A TypoLink or the link of a MenuItem links back to the default language (&L=0), 
# if the currently active language ID is greater than 2
# (useful for example if only languages 0 to 2 are available in the target page).
additionalParams = &L=0
additionalParams.if.value = 2
additionalParams.if.isGreaterThan.data = GPvar:L
Personal tools