Merge "[TASK] Increase version number"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / IfViewHelper.php
1 <?php
2
3 /* *
4 * This script is backported from the FLOW3 package "TYPO3.Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License, either version 3 *
8 * of the License, or (at your option) any later version. *
9 * *
10 * The TYPO3 project - inspiring people to share! *
11 * */
12
13
14 /**
15 * This view helper implements an if/else condition.
16 * @see Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode::convertArgumentValue() to find see how boolean arguments are evaluated
17 *
18 * = Conditions =
19 *
20 * As a condition is a boolean value, you can just use a boolean argument.
21 * Alternatively, you can write a boolean expression there.
22 * Boolean expressions have the following form:
23 * XX Comparator YY
24 * Comparator is one of: ==, !=, <, <=, >, >= and %
25 * The % operator converts the result of the % operation to boolean.
26 *
27 * XX and YY can be one of:
28 * - number
29 * - Object Accessor
30 * - Array
31 * - a ViewHelper
32 * Note: Strings at XX/YY are NOT allowed.
33 *
34 * <code title="condition example">
35 * <f:if condition="{rank} > 100">
36 * Will be shown if rank is > 100
37 * </f:if>
38 * <f:if condition="{rank} % 2">
39 * Will be shown if rank % 2 != 0.
40 * </f:if>
41 * <f:if condition="{rank} == {k:bar()}">
42 * Checks if rank is equal to the result of the ViewHelper "k:bar"
43 * </f:if>
44 * </code>
45 *
46 * = Examples =
47 *
48 * <code title="Basic usage">
49 * <f:if condition="somecondition">
50 * This is being shown in case the condition matches
51 * </f:if>
52 * </code>
53 *
54 * Everything inside the <f:if> tag is being displayed if the condition evaluates to TRUE.
55 *
56 * <code title="If / then / else">
57 * <f:if condition="somecondition">
58 * <f:then>
59 * This is being shown in case the condition matches.
60 * </f:then>
61 * <f:else>
62 * This is being displayed in case the condition evaluates to FALSE.
63 * </f:else>
64 * </f:if>
65 * </code>
66 * <output>
67 * Everything inside the "then" tag is displayed if the condition evaluates to TRUE.
68 * Otherwise, everything inside the "else"-tag is displayed.
69 * </output>
70 *
71 * <code title="inline notation">
72 * {f:if(condition: someCondition, then: 'condition is met', else: 'condition is not met')}
73 * </code>
74 * <output>
75 * The value of the "then" attribute is displayed if the condition evaluates to TRUE.
76 * Otherwise, everything the value of the "else"-attribute is displayed.
77 * </output>
78 *
79 *
80 * @api
81 */
82 class Tx_Fluid_ViewHelpers_IfViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractConditionViewHelper {
83
84 /**
85 * renders <f:then> child if $condition is true, otherwise renders <f:else> child.
86 *
87 * @param boolean $condition View helper condition
88 * @return string the rendered string
89 * @api
90 */
91 public function render($condition) {
92 if ($condition) {
93 return $this->renderThenChild();
94 } else {
95 return $this->renderElseChild();
96 }
97 }
98 }
99 ?>