ModuleTemplate
Backend controllers should use ModuleTemplateFactory::create()
to create instances of a
\TYPO3\.
API functions of the
Module can be used to add buttons to
the button bar. It also implements the
\TYPO3\
so values can be assigned to it in the actions.
- class ModuleTemplate
-
- Fully qualified name
-
\TYPO3\
CMS\ Backend\ Template\ Module Template
A class taking care of the "outer" HTML of a module, especially the doc header and other related parts.
- assign ( string $key, ?mixed $value)
-
Add a variable to the view data collection.
- param $key
-
the key
- param $value
-
the value
- Returns
-
TYPO3CMSBackendTemplate Module Template
- assignMultiple ( array $values)
-
Add multiple variables to the view data collection.
- param $values
-
the values
- Returns
-
TYPO3CMSBackendTemplate Module Template
- render ( string $templateFileName = '')
-
Render the module.
- param $templateFileName
-
the templateFileName, default: ''
- Returns
-
string
- renderResponse ( string $templateFileName = '')
-
Render the module and create an HTML 200 response from it. This is a lazy shortcut so controllers don't need to take care of this in the backend.
- param $templateFileName
-
the templateFileName, default: ''
- Returns
-
PsrHttp Message Response Interface
- setBodyTag ( string $bodyTag)
-
Set to something like '<body id="foo">' when a special body tag is needed.
- param $bodyTag
-
the bodyTag
- Returns
-
TYPO3CMSBackendTemplate Module Template
- setTitle ( string $title, string $context = '')
-
Title string of the module: "My module · Edit view"
- param $title
-
the title
- param $context
-
the context, default: ''
- Returns
-
TYPO3CMSBackendTemplate Module Template
- getDocHeaderComponent ( )
-
Get the DocHeader. Can be used in controllers to add custom buttons / menus / ... to the doc header.
- Returns
-
TYPO3CMSBackendTemplate Components Doc Header Component
- setForm ( string $formTag = '')
-
A "<form>" tag encapsulating the entire module, including doc-header.
- param $formTag
-
the formTag, default: ''
- Returns
-
TYPO3CMSBackendTemplate Module Template
- setModuleId ( string $moduleId)
-
Optional 'data-module-id="{moduleId}"' on first <div> in body.
Can be helpful in JavaScript.
- param $moduleId
-
the moduleId
- Returns
-
TYPO3CMSBackendTemplate Module Template
- setModuleName ( string $moduleName)
-
Optional 'data-module-name="{moduleName}"' on first <div> in body.
Can be helpful in JavaScript.
- param $moduleName
-
the moduleName
- Returns
-
TYPO3CMSBackendTemplate Module Template
- setModuleClass ( string $moduleClass)
-
Optional 'class="module {moduleClass}"' on first <div> in body.
Can be helpful styling modules.
- param $moduleClass
-
the moduleClass
- Returns
-
TYPO3CMSBackendTemplate Module Template
- addFlashMessage ( string $messageBody, string $messageTitle = '', \TYPO3\CMS\Core\Type\ContextualFeedbackSeverity $severity = \TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::OK, bool $storeInSession = true)
-
Creates a message object and adds it to the FlashMessageQueue.
These messages are automatically rendered when the view is rendered.
- param $messageBody
-
the messageBody
- param $messageTitle
-
the messageTitle, default: ''
- param $severity
-
the severity, default: TYPO3CMSCoreTypeContextualFeedbackSeverity::OK
- param $storeInSession
-
the storeInSession, default: true
- Returns
-
TYPO3CMSBackendTemplate Module Template
- setFlashMessageQueue ( \TYPO3\CMS\Core\Messaging\FlashMessageQueue $flashMessageQueue)
-
ModuleTemplate by default uses queue 'core.template.flashMessages'. Modules may want to maintain an own queue. Use this method to render flash messages of a non-default queue at the default position in module HTML output. Call this method before adding single messages with addFlashMessage().
- param $flashMessageQueue
-
the flashMessageQueue
- Returns
-
TYPO3CMSBackendTemplate Module Template
- setUiBlock ( bool $uiBlock)
-
UI block is a spinner shown during browser rendering phase of the module, automatically removed when rendering finished. This is done by default, but the UI block can be turned off when needed for whatever reason.
- param $uiBlock
-
the uiBlock
- Returns
-
TYPO3CMSBackendTemplate Module Template
-
Generates a module actions dropdown in the docheader button bar.
Creates a dropdown button on the LEFT side (group 0) containing navigation to submodules or module actions. The button label shows the currently active module/action.
- param $additionalQueryParams
-
the additionalQueryParams, default: []
- Returns
-
TYPO3CMSBackendTemplate Module Template
- addButtonToButtonBar ( \TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface $button, string $buttonPosition = 'left', int $buttonGroup = 1)
-
Shorthand method to add a new button to the button bar
- param $button
-
the button
- param $buttonPosition
-
the buttonPosition, default: 'left'
- param $buttonGroup
-
the buttonGroup, default: 1
- Returns
-
TYPO3CMSBackendTemplate Module Template
Example: Create and use a ModuleTemplate in an Extbase Controller
The following example is extracted from the example Extbase extension t3docs/blog-example . See the complete source code at t3doc/blog-example (GitHub).
<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use T3docs\BlogExample\Domain\Model\Post;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
class BackendController extends ActionController
{
protected function initializeModuleTemplate(
ServerRequestInterface $request,
): ModuleTemplate {
$view = $this->moduleTemplateFactory->create($request);
$context = '';
$this->modifyDocHeaderComponent($view, $context);
$view->setFlashMessageQueue($this->getFlashMessageQueue());
$view->setTitle(
$this->getLanguageService()->sL('blog_example.module.mod:mlang_tabs_tab'),
$context,
);
return $view;
}
public function showPostAction(Post $post): ResponseInterface
{
if (!$this->isCurrentPageSysfolder()) {
return $this->redirect('index');
}
$view = $this->initializeModuleTemplate($this->request);
$view->assign('post', $post);
return $view->renderResponse('ShowPost');
}
}