I am using the StandaloneView to output some data.
The problem I encountered is that the given TemplateRootPath is just ignored.
TYPO3 throws an exception saying that it looked for the template in
/typo3/public/typo3conf/ext//Resources/Private/Templates/
but the given TemplateRootPath is one folder further down in /printView/.
Maybe there is something that went over my head but I am looking for a fix for about one and a half hours now.
$standaloneView = TYPO3CMSCoreUtilityGeneralUtility::makeInstance(TYPO3CMSFluidViewStandaloneView::class);
$standaloneView->setLayoutRootPaths([
TYPO3CMSCoreUtilityGeneralUtility::getFileAbsFileName('EXT:<my-extension>/Resources/Private/Layouts/printView/'),
]);
$standaloneView->setPartialRootPaths([
TYPO3CMSCoreUtilityGeneralUtility::getFileAbsFileName('EXT:<my-extension>/Resources/Private/Partials'),
]);
$standaloneView->setTemplateRootPaths([
TYPO3CMSCoreUtilityGeneralUtility::getFileAbsFileName('EXT:<my-extension>/Resources/Private/Templates/printView/'),
]);
$standaloneView->setFormat('html');
$standaloneView->setTemplate('printView/printView');
$standaloneView->assignMultiple([
//variable assignment
]);
echo $standaloneView->render();
<my-extension> is there on purpose
2
Answers
set...RootPaths(...)
expects an array as parameter.Maybe you need to change the filename of the template to UpperCamelCase.
That might not be needed for the parameter you use for selection, but the generated filename will have it. (
PrintView.html
instead ofprintView.html
)It’s little bit late to the party, but as you already has the paths of your private resources declared within the TypoScript of your ext, you can just read them instead of rewriting (DRY!).
with imports
Just declare a method somewhere in your controller (to retrieve its context):
So finally you can use it in action(s) of sample
My
controller to render many different standalone views easily like:finally you can create these views in files:
typo3conf/ext/yourext/Resources/Private/Templates/My/Jumper/EverythingOk.html
typo3conf/ext/yourext/Resources/Private/Templates/My/Jumper/NotFound.html
and really finally, don’t forget to clear the cache 😀