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

CPS-IT / handlebars / 13521177515

25 Feb 2025 12:26PM UTC coverage: 88.385% (-4.9%) from 93.283%
13521177515

Pull #414

github

web-flow
Merge 65231cdd6 into 39f196173
Pull Request #414: [FEATURE] Introduce Handlebars view for Extbase context

0 of 66 new or added lines in 2 files covered. (0.0%)

1111 of 1257 relevant lines covered (88.39%)

4.14 hits per line

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

0.0
/Classes/Extbase/View/ExtbaseHandlebarsView.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars".
7
 *
8
 * Copyright (C) 2025 Elias Häußler <e.haeussler@familie-redlich.de>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace Fr\Typo3Handlebars\Extbase\View;
25

26
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
27
use TYPO3\CMS\Frontend;
28
use TYPO3Fluid\Fluid;
29

30
/**
31
 * ExtbaseHandlebarsView
32
 *
33
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
34
 * @license GPL-2.0-or-later
35
 */
36
final class ExtbaseHandlebarsView implements Fluid\View\ViewInterface
37
{
38
    /**
39
     * @param array<string, mixed> $contentObjectConfiguration
40
     */
NEW
41
    public function __construct(
×
42
        private readonly Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer,
43
        private array $contentObjectConfiguration,
NEW
44
    ) {}
×
45

NEW
46
    public function assign(string $key, mixed $value): self
×
47
    {
NEW
48
        if (\is_array($value)) {
×
NEW
49
            $key .= '.';
×
50
        }
51

NEW
52
        $this->contentObjectConfiguration['variables.'][$key] = $value;
×
53

NEW
54
        return $this;
×
55
    }
56

57
    /**
58
     * @param array<string, mixed> $values
59
     */
NEW
60
    public function assignMultiple(array $values): self
×
61
    {
NEW
62
        foreach ($values as $key => $value) {
×
NEW
63
            $this->assign($key, $value);
×
64
        }
65

NEW
66
        return $this;
×
67
    }
68

NEW
69
    public function render(): string
×
70
    {
NEW
71
        return $this->contentObjectRenderer->cObjGetSingle('HANDLEBARSTEMPLATE', $this->contentObjectConfiguration);
×
72
    }
73

74
    /**
75
     * @param array<string, mixed> $variables
76
     */
NEW
77
    public function renderSection($sectionName, array $variables = [], $ignoreUnknown = false): string
×
78
    {
79
        // This is a Fluid feature, sections are not available in Handlebars.
NEW
80
        return '';
×
81
    }
82

83
    /**
84
     * @param array<string, mixed> $variables
85
     */
NEW
86
    public function renderPartial($partialName, $sectionName, array $variables, $ignoreUnknown = false): string
×
87
    {
88
        // This is a Fluid feature, Handlebars renderer takes care of rendering partials.
NEW
89
        return '';
×
90
    }
91

NEW
92
    public function setTemplateName(string $templateName): self
×
93
    {
NEW
94
        $this->contentObjectConfiguration['templateName'] = $templateName;
×
95

NEW
96
        return $this;
×
97
    }
98

NEW
99
    public function setTemplateNameFromRequest(RequestInterface $request): self
×
100
    {
NEW
101
        return $this->setTemplateName(
×
NEW
102
            $request->getControllerName() . '/' . $request->getControllerActionName(),
×
NEW
103
        );
×
104
    }
105
}
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