PathProvider & VariableProvider
Two further interfaces allow contributing template paths and global variables
from PHP rather than from TypoScript or Services. configuration.
Both are auto-registered via
# and both use a
priority integer to control merge order.
PathProvider
Implement the \CPSIT\Typo3Handlebars\Renderer\Template\Path\PathProvider interface to contribute template and partial root paths programmatically — for example when paths depend on the current site configuration or a value not available at container compile time.
Higher priority values are merged last and therefore take precedence over lower
ones. The three built-in providers use 0 (
Global), 50
(
Typo), and 100 (
Content).
- interface PathProvider
-
- Fully qualified name
-
\CPSIT\
Typo3Handlebars\ Renderer\ Template\ Path\ Path Provider
- getTemplateRootPaths ( )
-
Return an array of template root paths, keyed by integer priority.
- returntype
-
array
- getPartialRootPaths ( )
-
Return an array of partial root paths, keyed by integer priority.
- returntype
-
array
namespace Vendor\Extension\Renderer\Template\Path;
use CPSIT\Typo3Handlebars\Renderer\Template\Path\PathProvider;
use TYPO3\CMS\Core\Site\SiteFinder;
final readonly class SitePathProvider implements PathProvider
{
public function __construct(
private SiteFinder $siteFinder,
) {}
public function getTemplateRootPaths(): array
{
return [];
}
public function getPartialRootPaths(): array
{
return [];
}
public function isCacheable(): bool
{
return false;
}
public static function getPriority(): int
{
return 25;
}
}
The class is picked up automatically because
Path carries
#. No extra
Services. entry is needed beyond standard autowiring.
VariableProvider
Implement the \CPSIT\Typo3Handlebars\Renderer\Variables\VariableProvider interface to inject variables into every template rendering without repeating them in TypoScript. Common uses include a site-wide locale string, feature flags, or shared navigation data.
Providers are merged in ascending priority order; a higher-priority provider
can overwrite keys from a lower-priority one. The built-in
Global uses priority 0.
- interface VariableProvider
-
- Fully qualified name
-
\CPSIT\
Typo3Handlebars\ Renderer\ Variables\ Variable Provider
namespace Vendor\Extension\Renderer\Variables;
use CPSIT\Typo3Handlebars\Renderer\Variables\VariableProvider;
use TYPO3\CMS\Core\Site\SiteFinder;
final readonly class SiteVariableProvider implements VariableProvider
{
public function __construct(
private SiteFinder $siteFinder,
) {}
public function get(): array
{
return [
'siteName' => $this->siteFinder->getSiteByPageId(0)->getIdentifier(),
];
}
public function offsetExists(mixed $offset): bool
{
return array_key_exists($offset, $this->get());
}
public function offsetGet(mixed $offset): mixed
{
return $this->get()[$offset] ?? null;
}
public function offsetSet(mixed $offset, mixed $value): never
{
throw new \LogicException('Variables are read-only.', 1781693633);
}
public function offsetUnset(mixed $offset): never
{
throw new \LogicException('Variables are read-only.', 1781693639);
}
public static function getPriority(): int
{
return 10;
}
}
Like
Path, the class is picked up automatically via
# on the interface.