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|int $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
- getView ( )
-
Deprecated: since v12, will be removed in v13.
- Returns
-
\TYPO3\
CMS\ Fluid\ View\ Standalone View
- setContent ( string $content)
-
Deprecated: since v12, will be removed in v13.
- param $content
-
the content
- Returns
-
self
- renderContent ( )
-
Deprecated: since v12, will be removed in v13. Remove together with $legacyView property and Templates/Module.html.
- Returns
-
string
- getBodyTag ( )
-
Deprecated: since v12, will be removed in v13.
Returns the current body tag.
- Returns
-
string
-
Deprecated: since v12, will be removed in v13.
Generates the Menu for things like Web->Info
- param $moduleMenuIdentifier
-
the moduleMenuIdentifier
- Returns
-
self
-
Generates a menu in the docheader to access third-level modules
- param $additionalQueryParams
-
the additionalQueryParams, default: []
- Returns
-
self
-
Deprecated: since v12, will be removed in v13.
Creates a tab menu where the tabs or collapsible are rendered with bootstrap markup
- param $menuItems
-
Tab elements, each element is an array with "label" and "content"
- param $domId
-
DOM id attribute, will be appended with an iteration number per tab.
- param $defaultTabIndex
-
Default tab to open (for toggle <=0). Value corresponds to integer-array index + 1(index zero is "1", index "1" is 2 etc.). A value of zero (or something non-existingwill result in no default tab open., default: 1
- param $collapsible
-
If set, the tabs are rendered as headers instead over each sheet. Effectively this meansthere is no tab menu, but rather a foldout/fold-in menu., default: false
- param $wrapContent
-
If set, the content is wrapped in div structure which provides a padding and borderstyle. Set this FALSE to get unstyled content pane with fullsize content area., default: true
- param $storeLastActiveTab
-
If set, the last open tab is stored in local storage and will be re-open again.If you don't need this feature, e.g. for wizards like import/export you candisable this behaviour., default: true
- Returns
-
string
- header ( string $text, bool $inlineEdit = true)
-
Deprecated: since v12, will be removed in v13.
Returns the header-bar in the top of most backend modules Closes section if open.
- param $text
-
The text string for the header
- param $inlineEdit
-
Whether the header should be editable (e.g. page title), default: true
- Return description
-
HTML content
- Returns
-
string
Example: Create and use a ModuleTemplate in an Extbase Controller
The following example is extracted from the example Extbase extension EXT: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);
$this->modifyDocHeaderComponent($view);
$view->setFlashMessageQueue($this->getFlashMessageQueue());
return $view;
}
public function showPostAction(Post $post): ResponseInterface
{
$view = $this->initializeModuleTemplate($this->request);
$view->assign('post', $post);
return $view->renderResponse('ShowPost');
}
}