@@ -481,3 +481,65 @@ ViewHelper's `renderStatic()` method you can replace the code like this:
481481 by calling `$this->renderingContext->getViewHelperInvoker()->invoke() ` instead.
482482
483483 See also :php: `TYPO3Fluid\F luid\C ore\V iewHelper\V iewHelperInvoker `.
484+
485+ .. _fluid-custom-viewhelper-access :
486+
487+ How to access classes in the ViewHelper implementation
488+ ======================================================
489+
490+ Custom ViewHelper implementations support
491+ `Dependency injection <https://docs.typo3.org/permalink/t3coreapi:dependency-injection >`_.
492+
493+ You can, for example, inject the :php-short: `\T YPO3\C MS\C ore\D atabase\C onnectionPool `
494+ to access the database by using the `database abstraction layer DBAL <https://docs.typo3.org/permalink/t3coreapi:doctrine-dbal >`_.
495+
496+ Some objects depend on the current context and can be fetched from
497+ the rendering context:
498+
499+ .. note ::
500+ This list is not complete, please help us with more examples.
501+
502+ .. _fluid-custom-viewhelper-access-request :
503+
504+ Accessing the current Request in a ViewHelper implementation
505+ ------------------------------------------------------------
506+
507+ You can use a `render() ` method in the ViewHelper implementation to get the
508+ current :php-short: `\P sr\H ttp\M essage\S erverRequestInterface ` object
509+ from the :php-short: `TYPO3\C MS\F luid\C ore\R endering\R enderingContext `:
510+
511+ .. code-block :: php
512+ :caption: EXT:my_extension/Classes/ViewHelpers/SomeViewHelper.php
513+
514+ public function render()
515+ {
516+ $request = $this->renderingContext->getRequest();
517+ return 'Hello World!';
518+ }
519+
520+ .. _fluid-custom-viewhelper-access-contentObject :
521+
522+ Using stdWrap / fetching the current ContentObject in a ViewHelper implementation
523+ ---------------------------------------------------------------------------------
524+
525+ You can `access the ContentObjectRenderer <https://docs.typo3.org/permalink/t3coreapi:tsfe-contentobjectrenderer >`_
526+ from the :php-short: `\P sr\H ttp\M essage\S erverRequestInterface `:
527+
528+ .. code-block :: php
529+ :caption: EXT:my_extension/Classes/ViewHelpers/SomeViewHelper.php
530+
531+ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
532+
533+ public function render()
534+ {
535+ $request = $this->renderingContext->getRequest();
536+ $cObj = $request->getAttribute('currentContentObject');
537+ return $cObj->stdWrap('Hello World', ['wrap' => '|!']);
538+ }
539+
540+ .. deprecated :: 13.4
541+ The class :php-short: `\T YPO3\C MS\F rontend\C ontroller\T ypoScriptFrontendController `
542+ and its global instance :php: `$GLOBALS['TSFE'] `, which were formerly used to fetch the
543+ ContentObjectRenderer, have been marked as
544+ deprecated. The class will be removed in TYPO3 v14. See
545+ `TSFE <https://docs.typo3.org/permalink/t3coreapi:tsfe >`_ for migration steps.
0 commit comments