[TASK] Merge submodule linkvalidator into core
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / IfViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 /**
15 * This view helper implements an if/else condition.
16 * Check \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::convertArgumentValue() to 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 * - a String
33 *
34 * <f:if condition="{rank} > 100">
35 * Will be shown if rank is > 100
36 * </f:if>
37 * <f:if condition="{rank} % 2">
38 * Will be shown if rank % 2 != 0.
39 * </f:if>
40 * <f:if condition="{rank} == {k:bar()}">
41 * Checks if rank is equal to the result of the ViewHelper "k:bar"
42 * </f:if>
43 * <f:if condition="{foo.bar} == 'stringToCompare'">
44 * Will result true if {foo.bar}'s represented value equals 'stringToCompare'.
45 * </f:if>
46 *
47 * = Examples =
48 *
49 * <code title="Basic usage">
50 * <f:if condition="somecondition">
51 * This is being shown in case the condition matches
52 * </f:if>
53 * </code>
54 * <output>
55 * Everything inside the <f:if> tag is being displayed if the condition evaluates to TRUE.
56 * </output>
57 *
58 * <code title="If / then / else">
59 * <f:if condition="somecondition">
60 * <f:then>
61 * This is being shown in case the condition matches.
62 * </f:then>
63 * <f:else>
64 * This is being displayed in case the condition evaluates to FALSE.
65 * </f:else>
66 * </f:if>
67 * </code>
68 * <output>
69 * Everything inside the "then" tag is displayed if the condition evaluates to TRUE.
70 * Otherwise, everything inside the "else"-tag is displayed.
71 * </output>
72 *
73 * <code title="inline notation">
74 * {f:if(condition: someCondition, then: 'condition is met', else: 'condition is not met')}
75 * </code>
76 * <output>
77 * The value of the "then" attribute is displayed if the condition evaluates to TRUE.
78 * Otherwise, everything the value of the "else"-attribute is displayed.
79 * </output>
80 *
81 * @see \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::convertArgumentValue()
82 * @api
83 */
84 class IfViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper {
85
86 /**
87 * renders <f:then> child if $condition is true, otherwise renders <f:else> child.
88 *
89 * @param boolean $condition View helper condition
90 * @return string the rendered string
91 * @api
92 */
93 public function render($condition) {
94 if ($condition) {
95 return $this->renderThenChild();
96 } else {
97 return $this->renderElseChild();
98 }
99 }
100 }
101
102 ?>