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.
Loading your own or other RequireJS modules
In case you use the ready event, you may wonder how to use the module.
Answer: it depends! If you use Fluid's f:
view helper
add the argument include
:
<f:be.pageRenderer includeRequireJsModules="{
0:'TYPO3/CMS/FooBar/Wisdom'
}" />
However, if you don't use Fluid you may use Page
in your controller:
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
$pageRenderer->loadRequireJsModule('TYPO3/CMS/FooBar/MyMagicModule');
Bonus: load
takes a second argument
$call
which is executed right after the module
was loaded. The callback function must be wrapped within function
:
$pageRenderer->loadRequireJsModule(
'TYPO3/CMS/FooBar/MyMagicModule',
'function() { console.log("Loaded own module."); }'
);