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
-
self
- assignMultiple ( array $values) ¶
-
Add multiple variables to the view data collection.
- param $values
-
the values
- Returns
-
self
- 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
-
\Psr\
Http\ 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
-
self
- setTitle ( string $title, string $context = '') ¶
-
Title string of the module: "My module · Edit view"
- param $title
-
the title
- param $context
-
the context, default: ''
- Returns
-
self
- getDocHeaderComponent ( ) ¶
-
Get the DocHeader. Can be used in controllers to add custom buttons / menus / ... to the doc header.
- Returns
-
\TYPO3\
CMS\ Backend\ Template\ Components\ Doc Header Component
- setForm ( string $formTag = '') ¶
-
A "<form>" tag encapsulating the entire module, including doc-header.
- param $formTag
-
the formTag, default: ''
- Returns
-
self
- setModuleId ( string $moduleId) ¶
-
Optional 'data-module-id="{moduleId}"' on first <div> in body.
Can be helpful in JavaScript.
- param $moduleId
-
the moduleId
- Returns
-
self
- setModuleName ( string $moduleName) ¶
-
Optional 'data-module-name="{moduleName}"' on first <div> in body.
Can be helpful in JavaScript.
- param $moduleName
-
the moduleName
- Returns
-
self
- setModuleClass ( string $moduleClass) ¶
-
Optional 'class="module {moduleClass}"' on first <div> in body.
Can be helpful styling modules.
- param $moduleClass
-
the moduleClass
- Returns
-
self
- 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
-
self
- 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
-
self
- 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
-
self
-
Generates a menu in the docheader to access third-level modules
- param $additionalQueryParams
-
the additionalQueryParams, default: []
- Returns
-
self
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).
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('LLL:EXT:blog_example/Resources/Private/Language/Module/locallang_mod.xlf:mlang_tabs_tab'),
$context,
);
return $view;
}
public function showPostAction(Post $post): ResponseInterface
{
$view = $this->initializeModuleTemplate($this->request);
$view->assign('post', $post);
return $view->renderResponse('ShowPost');
}
}