Extending Templates
Register the templates overrides in your extension's Extension class:
<?php
declare(strict_types=1);
namespace T3Docs\Typo3DocsTheme\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use function dirname;
class Typo3DocsThemeExtension extends Extension implements PrependExtensionInterface
{
/** @param mixed[] $configs */
public function load(array $configs, ContainerBuilder $container): void
{
}
public function prepend(ContainerBuilder $container): void
{
$loader = new PhpFileLoader(
$container,
new FileLocator(dirname(__DIR__, 2) . '/resources/config'),
);
$loader->load('your-extension.php');
$container->prependExtensionConfig('guides', [
'themes' => [
'typo3docs' => [
'extends' => 'bootstrap',
'templates' => [dirname(__DIR__, 2) . '/resources/template'],
],
],
]);
}
}
It is recommended to always extend an existing template so that the Twig files of the base templates can be used as fallback for non-defined specific template files.
In order to extend the default bootstrap theme, require the according base
extension in your extension's composer.json
:
{
"name": "t3docs/typo3-docs-theme",
"...": "...",
"require": {
"phpdocumentor/guides-theme-bootstrap": "dev-main"
}
}
And then set 'extends' => 'bootstrap'
(line 32 in the first code-snippet).
To extend the base template (plain HTML) require phpdocumentor/guides
in your
composer.json
, and omit the key extends
:
$container->prependExtensionConfig('guides', [
'themes' => ['mytheme' => dirname(__DIR__, 3) . '/resources/template'],
]);
You can now copy any Twig file from the extended extensions and change it with the full power of Twig.
Have a look at the custom theme for TYPO3 Documentation for an example on how to create a theme which also features custom directives.