1
|
|
|
<?php |
2
|
|
|
namespace TYPO3Fluid\Fluid\ViewHelpers; |
3
|
|
|
|
4
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
5
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; |
6
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Inline Fluid rendering ViewHelper |
10
|
|
|
* |
11
|
|
|
* Renders Fluid code stored in a variable, which you normally would |
12
|
|
|
* have to render before assigning it to the view. Instead you can |
13
|
|
|
* do the following (note, extremely simplified use case): |
14
|
|
|
* |
15
|
|
|
* $view->assign('variable', 'value of my variable'); |
16
|
|
|
* $view->assign('code', 'My variable: {variable}'); |
17
|
|
|
* |
18
|
|
|
* And in the template: |
19
|
|
|
* |
20
|
|
|
* {code -> f:inline()} |
21
|
|
|
* |
22
|
|
|
* Which outputs: |
23
|
|
|
* |
24
|
|
|
* My variable: value of my variable |
25
|
|
|
* |
26
|
|
|
* You can use this to pass smaller and dynamic pieces of Fluid code |
27
|
|
|
* to templates, as an alternative to creating new partial templates. |
28
|
|
|
*/ |
29
|
|
|
class InlineViewHelper extends AbstractViewHelper |
30
|
|
|
{ |
31
|
|
|
use CompileWithContentArgumentAndRenderStatic; |
32
|
|
|
|
33
|
|
|
protected $escapeChildren = false; |
34
|
|
|
|
35
|
|
|
protected $escapeOutput = false; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function initializeArguments() |
41
|
|
|
{ |
42
|
|
|
$this->registerArgument( |
43
|
|
|
'code', |
44
|
|
|
'string', |
45
|
|
|
'Fluid code to be rendered as if it were part of the template rendering it. Can be passed as inline argument or tag content' |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param array $arguments |
51
|
|
|
* @param \Closure $renderChildrenClosure |
52
|
|
|
* @param RenderingContextInterface $renderingContext |
53
|
|
|
* @return mixed|string |
54
|
|
|
*/ |
55
|
|
|
public static function renderStatic( |
56
|
|
|
array $arguments, |
57
|
|
|
\Closure $renderChildrenClosure, |
58
|
|
|
RenderingContextInterface $renderingContext |
59
|
|
|
) { |
60
|
|
|
return $renderingContext->getTemplateParser()->parse($renderChildrenClosure())->render($renderingContext); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|