Bug #105496
closedCreate a backend module with Extbase according to documents leads to exception
0%
Description
Following instructions on: https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/HowTo/BackendModule/CreateModuleWithExtbase.html#backend-modules-template
A simple backend controller action in TYPO3 13.4.0 leads to:
Call to undefined method TYPO3\CMS\Backend\Template\ModuleTemplate::setContent()
The example controller in my case would look like:
<?php declare(strict_types=1); namespace In2code\Lux\Controller; use TYPO3\CMS\Backend\Attribute\AsController; use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; #[AsController] final class AnalysisController extends ActionController { public function __construct( protected readonly ModuleTemplateFactory $moduleTemplateFactory, ) { } public function dashboardAction(): ResponseInterface { $this->view->assign('someVar', 'someContent'); $moduleTemplate = $this->moduleTemplateFactory->create($this->request); // Adding title, menus, buttons, etc. using $moduleTemplate ... $moduleTemplate->setContent($this->view->render()); return $this->htmlResponse($moduleTemplate->renderContent()); } }
Updated by Garvin Hicking about 22 hours ago
- Category set to Documentation
- Status changed from New to Closed
Indeed this is missing in the docs. I've created an issue on the documentation tracker: https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/issues/4962
The old moduleTemplate API has been removed: https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Deprecation-96903-DeprecateOldModuleTemplateAPI.html
Most likely you should be able to use:
public function dashboardAction(): ResponseInterface { $moduleTemplate = $this->moduleTemplateFactory->create($this->request); $moduleTemplate->assign('someVar', 'someContent'); return $moduleTemplate->renderResponse('MyTemplate'); }
with an accompanying Layout file as outlined in https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Feature-96730-SimplifiedExtbackendModuleTemplateAPI.html
HTH!