Feature: #96730 - Simplified ext:backend ModuleTemplate API
See forge#96730
Description
Extensions that deliver own backend modules can now use the
\TYPO3\
class as
view for the 'body' part of the view and do not need to
instantiate an own view anymore.
The default document header of Module
can be rendered
using a new Fluid layout named Module
.
Impact
The standard code within backend module related controllers looked like this until now:
$moduleTemplate = $this->moduleTemplateFactory->create($request);
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplateRootPaths(['EXT:my_extension/Resources/Private/Templates']);
$view->assign('aVariable', 'aValue');
$moduleTemplate->setContent($view->render('MyTemplate'));
return $this->responseFactory->createResponse()
->withHeader('Content-Type', 'text/html; charset=utf-8')
->withBody($this->streamFactory->createStream($moduleTemplate->renderContent($templateFileName)));
This can be streamlined as shown below. Template paths (Templates, Layouts, Partials)
are configured automatically, calling render
will look for file
Resources/
. Templates can be
overridden by other extensions using page TSconfig, see this changelog entry
for details on this.
$moduleTemplate = $this->moduleTemplateFactory->create($request);
$moduleTemplate->assign('aVariable', 'aValue');
return $moduleTemplate->renderResponse('MyTemplate');
The HTML template should then reference the ModuleTemplate layout:
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Module" />
<f:section name="Content">
My body content
</f:section>
</html>