Feature: #96812 - Override backend templates with TSconfig¶
See forge#96812
Description¶
Introduction¶
All Fluid templates rendered by backend controllers can be overridden with own templates on a per-file basis.
This can be configured using TSconfig: Both page TSconfig and user TSconfig are observed. The feature is available for basically all Core backend modules, as well as the backend main frame templates. Exceptions are email templates and templates of the install tool.
This feature was previously available in a similar way for some specifically crafted backend controllers, namely the dashboard extension and the page module. It was based on frontend TypoScript in combination with Extbase magic. This has been superseded by the new TSconfig based approach. Instances using the old solution need an adaption. Please find details in the changelog entry.
Note
While this feature is powerful and allows overriding nearly any backend
template, it should be used with care: Fluid templates of the Core
extensions are not considered API. The Core development needs the
freedom to add, change and delete Fluid templates any time, even for
bugfix releases. Template overrides are similar to an XCLASS
in
PHP - the Core can not guarantee integrity on this level across versions.
Basic syntax¶
The various combinations are best explained by example: The linkvalidator
extension (its Composer name is "typo3/cms-linkvalidator") comes with a backend
module in the Web main section. The page tree is displayed for this module and
linkvalidator has two main views and templates: Resources/
for the "Report" view and another one for the "Check link" view. To override
the Backend/
with an own template, this definition can
be added to an extension's Configuration/
file
(see changelog):
# Pattern: templates."composer-name"."something-unique" = "overriding-extension-composer-name":"entry-path"
templates.typo3/cms-linkvalidator.1643293191 = my-vendor/my-extension:Resources/Private/TemplateOverrides
When the target extension identified by its Composer name "my-vendor/my-extension" provides the file
Resources/
, this file will
be used instead of the default template file from the linkvalidator extension.
All Core extensions stick to the general templates, layouts and partial file and directory position structure.
When an extension needs to override a partial that is located in Resources/
,
and an override has been specified like above to my-
, the
system will look for file Resources/
. Similar for layouts.
The path part of the override definition can be set to whatever an integrator prefers,
Resources/
is just an idea here and hopefully not a bad one,
further details rely on additional needs. For instance, it is probably a good idea to include
the Composer or extension name of the source extension in the path (linkvalidator in our example),
or when using overrides based on page IDs or group IDs, to include those in the path. The source
extension sub-path is automatically added by the system when looking for override files, when
a layout file is located at Resources/
, and an
override definition uses path Resources/
, the system
will look up Resources/
.
Templates overrides are based on file existence: Two files are never merged. An override definition either kicks in because it actually supplies a file at the correct position with the correct file name, or it doesn't and the default is used. This can become unhandy for big template files. In such cases it might be an option to request a split of a big template file into smaller partial files, so an extension can override a dedicated partial only.
When multiple override paths are defined and more than one of them have overrides for a specific template, the override definition with the highest numerical value wins:
templates.typo3/cms-linkvalidator.23 = other-vendor/other-extension:Resources/Private/TemplateOverrides/Linkvalidator
templates.typo3/cms-linkvalidator.2300 = my-vendor/my-extension:Resources/Private/MyOverrideIsBigger
Due to the nature of TSconfig, and its two shapes page TSconfig and user TSconfig, various combinations are possible:
- Define "global" overrides with page TSconfig in
page.
of an extension. This works for all modules, no matter if the module renders a page tree or not.tsconfig - Define overrides on page level using the
TSconfig
field of page records. As always with page TSconfig, sub pages and sub trees inherit these settings from parent pages. - Define overrides on user or (better) group level. As always, User TSconfig can override
page TSconfig by prefixing any setting available as page TSconfig with
page.
in user TSconfig. So a user TSconfig template override starts withpage.
instead oftemplates. templates.
.
Usage in own modules¶
Extensions with backend modules that use the Simplified backend module template API automatically enable the general backend template override feature. Extension authors do not need to further prepare their extensions to allow template overrides by other extensions.
Impact¶
Third-party or custom extensions like a site extension can now change backend templates if needed. This can be handy, for instance, to give editors custom hints in certain areas without custom PHP code, or to do some other quick solutions.
Some Core extensions like the dashboard also use this feature when third-party extensions supply additional widgets with templates to register those templates into the dashboard namespace. See the dashboard extension documentation and this changelog for more details.
This feature needs to be used with care since the Core does not consider templates as API and a template override may thus break anytime.