.. include:: /Includes.rst.txt .. _typo3fluid-fluid-if: ====================== if ViewHelper `` ====================== This ViewHelper implements an if/else condition. Fluid Boolean Rules / Conditions: ================================= A condition is evaluated as a boolean value, so you can use any boolean argument, like a variable. Alternatively, you can use a full boolean expression. The entered expression is evaluated as a PHP expression. You can combine multiple expressions via :php:`&&` (logical AND) and :php:`||` (logical OR). An expression can also be prepended with the :php:`!` ("not") character, which will negate that expression. Have a look into the Fluid section of the "TYPO3 Explained" Documentation for more details about complex conditions. Boolean expressions have the following form: `is true` variant: `{variable}`:: Will be shown if foo is truthy. or `is false` variant: `!{variable}`:: Will be shown if foo is falsy. or comparisons with expressions:: XX Comparator YY Comparator is one of: :php:`==, !=, <, <=, >, >=` and :php:`%` The :php:`%` operator (modulo) converts the result of the operation to boolean. `XX` and `YY` can be one of: - Number - String - Object Accessor (`object.property`) - Array - a ViewHelper :: Will be shown if rank is > 100 Will be shown if rank % 2 != 0. Checks if rank is equal to the result of the ViewHelper "k:bar" Will result in true if {object.property}'s represented value equals 'stringToCompare'. Examples ======== Basic usage ----------- :: This is being shown in case the condition matches Output:: Everything inside the tag is being displayed if the condition evaluates to TRUE. If / then / else ---------------- :: This is being shown in case the condition matches. This is being displayed in case the condition evaluates to FALSE. Output:: Everything inside the "then" tag is displayed if the condition evaluates to TRUE. Otherwise, everything inside the "else" tag is displayed. Inline notation --------------- :: {f:if(condition: someCondition, then: 'condition is met', else: 'condition is not met')} Output:: The value of the "then" attribute is displayed if the condition evaluates to TRUE. Otherwise, everything the value of the "else" attribute is displayed. Combining multiple conditions ----------------------------- :: This is being shown in case both conditions match. This is being displayed in case the first block of the condition evaluates to TRUE and any condition in the second condition block evaluates to TRUE. This is being displayed when none of the above conditions evaluated to TRUE. Output:: Depending on which expression evaluated to TRUE, that value is displayed. If no expression matched, the contents inside the final "else" tag are displayed. .. _typo3fluid-fluid-if_arguments: Arguments ========= .. _if_then: then ---- :aspect:`DataType` mixed :aspect:`Required` false :aspect:`Description` Value to be returned if the condition if met. .. _if_else: else ---- :aspect:`DataType` mixed :aspect:`Required` false :aspect:`Description` Value to be returned if the condition if not met. .. _if_condition: condition --------- :aspect:`DataType` boolean :aspect:`Required` false :aspect:`Description` Condition expression conforming to Fluid boolean rules