forked from TYPO3/Fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfViewHelper.php
More file actions
115 lines (111 loc) · 2.98 KB
/
IfViewHelper.php
File metadata and controls
115 lines (111 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace TYPO3Fluid\Fluid\ViewHelpers;
/*
* This file belongs to the package "TYPO3 Fluid".
* See LICENSE.txt that was shipped with this package.
*/
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
/**
* This ViewHelper implements an if/else condition.
*
* Conditions:
*
* As a condition is a boolean value, you can just use a boolean argument.
* Alternatively, you can write a boolean expression there.
* Boolean expressions have the following form:
*
* XX Comparator YY
*
* Comparator is one of: ==, !=, <, <=, >, >= and %
* The % operator converts the result of the % operation to boolean.
*
* XX and YY can be one of:
*
* - number
* - Object Accessor
* - Array
* - a ViewHelper
* - string
*
* ::
*
* <f:if condition="{rank} > 100">
* Will be shown if rank is > 100
* </f:if>
* <f:if condition="{rank} % 2">
* Will be shown if rank % 2 != 0.
* </f:if>
* <f:if condition="{rank} == {k:bar()}">
* Checks if rank is equal to the result of the ViewHelper "k:bar"
* </f:if>
* <f:if condition="{foo.bar} == 'stringToCompare'">
* Will result in true if {foo.bar}'s represented value equals 'stringToCompare'.
* </f:if>
*
* Examples
* ========
*
* Basic usage
* -----------
*
* ::
*
* <f:if condition="somecondition">
* This is being shown in case the condition matches
* </f:if>
*
* Output::
*
* Everything inside the <f:if> tag is being displayed if the condition evaluates to TRUE.
*
* If / then / else
* ----------------
*
* ::
*
* <f:if condition="somecondition">
* <f:then>
* This is being shown in case the condition matches.
* </f:then>
* <f:else>
* This is being displayed in case the condition evaluates to FALSE.
* </f:else>
* </f:if>
*
* 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.
*
* @api
*/
class IfViewHelper extends AbstractConditionViewHelper
{
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('condition', 'boolean', 'Condition expression conforming to Fluid boolean rules', false, false);
}
/**
* @param array $arguments
* @param RenderingContextInterface $renderingContext
* @return bool
*/
public static function verdict(array $arguments, RenderingContextInterface $renderingContext)
{
return (bool)$arguments['condition'];
}
}