• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / flux / 15918415903

20 May 2025 10:36AM UTC coverage: 91.109% (-2.1%) from 93.21%
15918415903

push

github

NamelessCoder
[TASK] Lock phpstan version

6927 of 7603 relevant lines covered (91.11%)

9.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/Classes/ViewHelpers/InlineViewHelper.php
1
<?php
2
declare(strict_types=1);
3
namespace FluidTYPO3\Flux\ViewHelpers;
4

5
/*
6
 * This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.md file that was distributed with this source code.
10
 */
11

12
use TYPO3Fluid\Fluid\Core\Parser\Source;
13
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
14
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
15

16
/**
17
 * Inline Fluid rendering ViewHelper
18
 *
19
 * Renders Fluid code stored in a variable, which you normally would
20
 * have to render before assigning it to the view. Instead you can
21
 * do the following (note, extremely simplified use case):
22
 *
23
 *      $view->assign('variable', 'value of my variable');
24
 *      $view->assign('code', 'My variable: {variable}');
25
 *
26
 * And in the template:
27
 *
28
 *      {code -> flux:inline()}
29
 *
30
 * Which outputs:
31
 *
32
 *      My variable: value of my variable
33
 *
34
 * You can use this to pass smaller and dynamic pieces of Fluid code
35
 * to templates, as an alternative to creating new partial templates.
36
 */
37
class InlineViewHelper extends AbstractViewHelper
38
{
39
    /**
40
     * @var boolean
41
     */
42
    protected $escapeChildren = false;
43

44
    /**
45
     * @var boolean
46
     */
47
    protected $escapeOutput = false;
48

49
    public function initializeArguments(): void
50
    {
51
        $this->registerArgument(
1✔
52
            'code',
1✔
53
            'string',
1✔
54
            'Fluid code to be rendered as if it were part of the template rendering it. '
1✔
55
                . 'Can be passed as inline argument or tag content'
1✔
56
        );
1✔
57
    }
58

59
    /**
60
     * @return mixed
61
     */
62
    public function render()
63
    {
64
        return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
2✔
65
    }
66

67
    /**
68
     * @return mixed
69
     */
70
    public static function renderStatic(
71
        array $arguments,
72
        \Closure $renderChildrenClosure,
73
        RenderingContextInterface $renderingContext
74
    ) {
75
        $source = (string) ($arguments['code'] ?? $renderChildrenClosure());
2✔
76
        return $renderingContext->getTemplateParser()
2✔
77
            ->parse(class_exists(Source::class) ? new Source($source) : $source)
2✔
78
            ->getRootNode()
2✔
79
            ->evaluate($renderingContext);
2✔
80
    }
81

82
    public function getContentArgumentName(): ?string
83
    {
84
        return 'code';
×
85
    }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc