Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
The Backend Template View (core)
This page covers the backend template view, using only core functionality without Extbase.
Tip
If you want to do extensive data modeling you may want to use Extbase templating. If you build a simple backend module it makes sense to work without Extbase.
Basic controller
When creating a controller without Extbase an instance of Module
is required
to return the rendered template:
class ListController
{
protected StandaloneView $view;
protected ModuleTemplate $moduleTemplate;
/**
* Constructor Method
*
* @param ModuleTemplate $moduleTemplate
*/
public function __construct(ModuleTemplate $moduleTemplate = null)
{
$this->view = GeneralUtility::makeInstance(StandaloneView::class);
$this->moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class);
}
// ...
}
Main entry point
handle
method is the main entry point which triggers only the allowed actions.
This makes it possible to include e.g. Javascript for all actions in the controller.
public function handleRequest(ServerRequestInterface $request): ResponseInterface
{
$action = (string)($request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index');
/**
* Define allowed actions
*/
if (!in_array($action, ['index'], true)) {
return new HtmlResponse('Action not allowed', 400);
}
/**
* Configure template paths for your backend module
*/
$this->view->setTemplateRootPaths(['EXT:extension_key/Resources/Private/Templates/List']);
$this->view->setPartialRootPaths(['EXT:extension_key/Resources/Private/Partials/']);
$this->view->setLayoutRootPaths(['EXT:extension_key/Resources/Private/Layouts/']);
$this->view->setTemplate($action);
/**
* Call the passed in action
*/
$result = $this->{$action . 'Action'}($request);
if ($result instanceof ResponseInterface) {
return $result;
}
/**
* Render template and return html content
*/
$this->moduleTemplate->setContent($this->view->render());
return new HtmlResponse($this->moduleTemplate->renderContent());
}
Actions
Now create an index
and assign variables to your view as you would normally do
public function indexAction()
{
$this->setDocHeader('index');
$this->view->assignMultiple(
[
'some-variable' => 'some-value',
]
);
}
The DocHeader
To add a DocHeader button use $this->module
and make
to create the button. Finally use add
to add it.
private function setDocHeader(string $active) {
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
$list = $buttonBar->makeLinkButton()
->setHref('<uri-builder-path>')
->setTitle('A Title')
->setShowLabelText('Link')
->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-extension-import', Icon::SIZE_SMALL));
$buttonBar->addButton($list, ButtonBar::BUTTON_POSITION_LEFT, 1);
}
Template example
Default layout
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:render section="content" />
</html>
Index template
<f:layout name="Default" />
<f:section name="content">
...
</f:section>