Feature: #66709 - Add TemplateRootPaths support to Fluid/View/StandaloneView¶
See forge#66709
Description¶
The StandaloneView is extended with set
and set
.
Now you can set a template by name.
When set
is called the $template
is used to find the template in the given
templateRootPaths with the same fallback logic as layoutRootPath and partialRootPath.
Basic example:
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setLayoutRootPaths($layoutPaths);
$view->setPartialRootPaths($partialPaths);
$view->setTemplateRootPaths($templatePaths);
try {
$view->setTemplate($templateName);
} catch (InvalidTemplateResourceException $e) {
// no template $templateName found in given $templatePaths
exit($e->getMessage());
}
$content = $view->render();
Copied!
Example of rendering an email template:
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setLayoutRootPaths(array(GeneralUtility::getFileAbsFileName('EXT:my_extension/Resources/Private/Layouts')));
$view->setPartialRootPaths(array(GeneralUtility::getFileAbsFileName('EXT:my_extension/Resources/Private/Partials')));
$view->setTemplateRootPaths(array(GeneralUtility::getFileAbsFileName('EXT:my_extension/Resources/Private/Templates')));
$view->setTemplate('Email/Notification');
$emailBody = $view->render();
Copied!
Impact¶
- The public API of
TYPO3\
is enhanced with the methodsCMS\ Fluid\ View\ Standalone View set
andTemplate Root Paths ($template Paths) set
Template ($template Name, $throw Exception = TRUE)