forked from TYPO3/Fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInlineViewHelper.php
62 lines (56 loc) · 1.81 KB
/
InlineViewHelper.php
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
<?php
namespace TYPO3Fluid\Fluid\ViewHelpers;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
/**
* Inline Fluid rendering ViewHelper
*
* Renders Fluid code stored in a variable, which you normally would
* have to render before assigning it to the view. Instead you can
* do the following (note, extremely simplified use case):
*
* $view->assign('variable', 'value of my variable');
* $view->assign('code', 'My variable: {variable}');
*
* And in the template:
*
* {code -> f:inline()}
*
* Which outputs:
*
* My variable: value of my variable
*
* You can use this to pass smaller and dynamic pieces of Fluid code
* to templates, as an alternative to creating new partial templates.
*/
class InlineViewHelper extends AbstractViewHelper
{
use CompileWithContentArgumentAndRenderStatic;
protected $escapeChildren = false;
protected $escapeOutput = false;
/**
* @return void
*/
public function initializeArguments()
{
$this->registerArgument(
'code',
'string',
'Fluid code to be rendered as if it were part of the template rendering it. Can be passed as inline argument or tag content'
);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return mixed|string
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
return $renderingContext->getTemplateParser()->parse($renderChildrenClosure())->render($renderingContext);
}
}