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

FluidTYPO3 / vhs / 30001290505

23 Jul 2026 10:57AM UTC coverage: 70.309% (-1.7%) from 72.022%
30001290505

push

github

NamelessCoder
[TER] 8.0.0

4819 of 6854 relevant lines covered (70.31%)

6.54 hits per line

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

52.94
/Classes/ViewHelpers/Page/Header/TitleViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Page\Header;
3

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

11
use FluidTYPO3\Vhs\Core\ViewHelper\AbstractViewHelper;
12
use FluidTYPO3\Vhs\Traits\PageRendererTrait;
13
use FluidTYPO3\Vhs\Utility\ContextUtility;
14
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
15

16
/**
17
 * ### ViewHelper used to override page title
18
 *
19
 * This ViewHelper uses the TYPO3 PageRenderer to set the
20
 * page title - with everything this implies regarding
21
 * support for TypoScript settings.
22
 *
23
 * Specifically you should note the setting `config.noPageTitle`
24
 * which must be set to either 1 (one) in case no other source
25
 * defines the page title (it's likely that at least one does),
26
 * or 2 (two) to indicate that the TS-controlled page title
27
 * must be disabled. A value of 2 (two) ensures that the title
28
 * used in this ViewHelper will be used in the rendered page.
29
 *
30
 * If you use the ViewHelper in a plugin it has to be USER
31
 * not USER_INT, what means it has to be cached!
32
 *
33
 * #### Why can I not forcibly override the title?
34
 *
35
 * This has been opted out with full intention. The reasoning
36
 * behind not allowing a Fluid template to forcibly override the
37
 * page title that may be set through TypoScript is that many
38
 * other extensions (mainly SEO-focused ones) will be setting
39
 * and manipulating the page title - and if overridden in a
40
 * template file using a ViewHelper, it would be almost impossible
41
 * to detect unless you already know exactly where to look.
42
 * Enforcing use of the core behavior is the only way to ensure
43
 * that this ViewHelper can coexist with other extensions in
44
 * a fully controllable way.
45
 */
46
class TitleViewHelper extends AbstractViewHelper
47
{
48
    use PageRendererTrait;
49

50
    public function initializeArguments(): void
51
    {
52
        $this->registerArgument('title', 'string', 'Title tag content');
3✔
53
        $this->registerArgument(
3✔
54
            'whitespaceString',
3✔
55
            'string',
3✔
56
            'String used to replace groups of white space characters, one replacement inserted per group',
3✔
57
            false,
3✔
58
            ' '
3✔
59
        );
3✔
60
        $this->registerArgument('setIndexedDocTitle', 'boolean', 'Set indexed doc title to title', false, false);
3✔
61
    }
62

63
    /**
64
     * @return mixed
65
     */
66
    public static function renderStatic(
67
        array $arguments,
68
        \Closure $renderChildrenClosure,
69
        RenderingContextInterface $renderingContext
70
    ) {
71
        if (ContextUtility::isBackend()) {
×
72
            return;
×
73
        }
74

75
        /** @var string $title */
76
        $title = $arguments['title'] ?? $renderChildrenClosure();
×
77

78
        /** @var string $whitespace */
79
        $whitespace = $arguments['whitespaceString'];
×
80
        $title = trim((string) preg_replace('/\s+/u', $whitespace, $title), $whitespace);
×
81
        static::getPageRenderer()->setTitle($title);
×
82
        if ($arguments['setIndexedDocTitle']) {
×
83
            $GLOBALS['TSFE']->indexedDocTitle = $title;
×
84
        }
85
    }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc