[FEATURE] Add templateRootPaths support to StandaloneView
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Documentation / Changelog / master / Feature-66709-AddTemplateRootPathsSupportToFluidViewStandaloneView.rst
1 ============================================================================
2 Feature: #66709 - Add TemplateRootPaths support to Fluid/View/StandaloneView
3 ============================================================================
4
5 Description
6 ===========
7
8 The StandaloneView is extended with ``setTemplateRootPaths($templatePaths)`` and ``setTemplate($templateName, $throwException = TRUE)``. Now you can set a template by name.
9
10 When ``setTemplate($templateName)`` is called the ``$templateName`` is used to find the template in the given templateRootPaths with the same fallback logic as layoutRootPath and partialRootPath.
11
12
13 Basic example:
14
15 .. code-block:: php
16
17 $view = GeneralUtility::makeInstance(StandaloneView::class);
18 $view->setLayoutRootPaths($layoutPaths);
19 $view->setPartialRootPaths($partialPaths);
20 $view->setTemplateRootPaths($templatePaths);
21
22 try {
23 $view->setTemplate($templateName);
24 } catch (InvalidTemplateResourceException $e) {
25 // no template $templateName found in given $templatePaths
26 exit($e->getMessage());
27 }
28
29 $content = $view->render();
30
31
32
33 Example of rendering a email template:
34
35 .. code-block:: php
36
37 $view = GeneralUtility::makeInstance(StandaloneView::class);
38 $view->setLayoutRootPaths(array(GeneralUtility::getFileAbsFileName('EXT:my_extension/Resources/Private/Layouts')));
39 $view->setPartialRootPaths(array(GeneralUtility::getFileAbsFileName('EXT:my_extension/Resources/Private/Partials')));
40 $view->setTemplateRootPaths(array(GeneralUtility::getFileAbsFileName('EXT:my_extension/Resources/Private/Templates')));
41 $view->setTemplate('Email/Notification');
42
43 $emailBody = $view->render();
44
45
46 Impact
47 ======
48
49 The public API of ``TYPO3\CMS\Fluid\View\StandaloneView`` is enhanced with the methods ``setTemplateRootPaths($templatePaths)`` and ``setTemplate($templateName, $throwException = TRUE)``