De:TSref/if
From TYPO3Wiki
| TypoScript Referenz - if |
|
||||
This page is document in progress. TypoScript (Liste TypoScript)weitere Typoscript Funktionen
[edit] if
Quelle: http://typo3.org/documentation/document-library/references/doc_core_tsref/current/view/5/7/
Diese Funktion gibt true zurück, wenn alle vorhandenen Bedingungen erfüllt sind (die Bedingungen werden mit AND verknüpft). Wenn irgendein Ausdruck zu false ausgewertet wird, dann gibt if false zurück.
Der Rückgabewert kann durch die .negate Eigenschaft in das Gegenteil überführt werden.
| Eigenschaft | Datentyp | Kommentar | Standardwert |
| isTrue | str /stdWrap | Wenn ein Inhalt (string) vorhanden / nicht leer ist, bzw. eine Zahl ungleich 0 ist. |
- |
| isFalse | str /stdWrap | Wenn der Inhalt 0 oder ein leerer String ist. |
- |
| isPositive | int /stdWrap
+ calc | Erwartet eine Zahl, wenn die Zahl nicht größer gleich 0 ist, dann wird false zurückgegeben. |
-
|
| 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]
[edit] Beispiele:
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
}
...
# Beispiel:
# Wenn das Content-Element mit der ID 29 gerendert werden soll, dann
# wird via Typoscript eine zusätzliche Funktionalität hinzugefügt
page.20 = HTML
page.20 {
# value ist vom Typ string / stdWrap
# Hier wird value sowohl ein Wert (string) zugewiesen
# als auch durch den stdWrap zusätzliche Funktionalität
# hinzugefügt wird.
value = zurück
value.typolink.parameter = 28
value.wrap = <div style="text-align:right;">|</div>
# Nur Anzeigen, wenn das Content-Element die ID 29 hat
# Wenn das Feld "uid" gleich dem Wert 29 ist, dann gibt
# if ein true zurück und das Element wird angezeigt.
# sonst nicht.
value.if.value.field = uid
value.if.equals = 29
}
# Beispiel: if.isInList.field = uid # value ist die Liste! if.value = 1,2,34,50,87
# Beispiel: # Querystring-Parameter als Bedingung # Ein TypoLink oder der Link eines MenuItems rufen gezielt die Defaultsprache auf (&L=0), # wenn aktuell eine Sprache-ID größer 2 aktiv ist (wenn z.B. in der Zielseite nur die Sprachen 0 bis 2 umgesetzt wurden). additionalParams = &L=0 additionalParams.if.value = 2 additionalParams.if.isGreaterThan.data = GPvar:L
