簡體   English   中英

TYPO3 在后端渲染 FLUID 模板

[英]TYPO3 Render FLUID Template in Backend

我有這個 TCA 的 extbase 擴展:

$GLOBALS['TCA']['tt_content']['types']['list']['previewRenderer']['items_item']
= \Vendor\Name\Backend\Preview\PreviewRenderer::class;

這個tsconfig:

mod.web_layout.tt_content.preview.list.items_item = EXT:EXT/Resources/Private/Templates/Preview/Items.html

如果我在這個模板文件中編寫完整的代碼,一切都會很好。 但是如果我改變它並使用這樣的Partials:

<f:render arguments="{_all}" partial="Preview/List"/>

我只收到以下錯誤:

Error while rendering FluidTemplate preview using /typo3conf/ext/EXT/Resources/Private/Templates/Preview/Items.html The Fluid template files "" could not be loaded.

如何設置部分和布局路徑? 我已經通過打字稿嘗試了使用模塊的ist,但它不起作用。

這取決於您的 PreviewRender 在做什么。

StandardContentPreviewRenderer僅支持模板文件,無布局,無局部。 它使用FluidStandaloneView並且只設置setTemplatePathAndFilename()而不為模板的其他部分設置路徑( renderContentElementPreviewFromFluidTemplate() ):

 protected function ‪renderContentElementPreviewFromFluidTemplate(array $row): ?string
 {
     $tsConfig = BackendUtility::getPagesTSconfig($row['pid'])['mod.']['web_layout.']['tt_content.']['preview.'] ?? [];
     $fluidTemplateFile = '';

     if ($row['CType'] === 'list' && !empty($row['list_type'])
         && !empty($tsConfig['list.'][$row['list_type']])
     ) {
         $fluidTemplateFile = $tsConfig['list.'][$row['list_type']];
     } elseif (!empty($tsConfig[$row['CType']])) {
         $fluidTemplateFile = $tsConfig[$row['CType']];
     }

     if ($fluidTemplateFile) {
         $fluidTemplateFile = GeneralUtility::getFileAbsFileName($fluidTemplateFile);
         if ($fluidTemplateFile) {
             try {
                 $view = GeneralUtility::makeInstance(StandaloneView::class);
                 $view->setTemplatePathAndFilename($fluidTemplateFile);
                 $view->assignMultiple($row);
                 if (!empty($row['pi_flexform'])) {
                     $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
                     $view->assign('pi_flexform_transformed', $flexFormService->convertFlexFormContentToArray($row['pi_flexform']));
                 }
                 return $view->render();
             } catch (\‪Exception $e) {
                 $this->logger->warning('The backend preview for content element {uid} can not be rendered using the Fluid template file "{file}"', [
                     'uid' => $row['uid'],
                     'file' => $fluidTemplateFile,
                     'exception' => $e,
                 ]);

                 if (‪$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->‪getBackendUser()->isAdmin()) {
                     $view = GeneralUtility::makeInstance(StandaloneView::class);
                     $view->assign('error', [
                         'message' => str_replace(‪Environment::getProjectPath(), '', $e->getMessage()),
                         'title' => 'Error while rendering FluidTemplate preview using ' . str_replace(‪Environment::getProjectPath(), '', $fluidTemplateFile),
                     ]);
                     $view->setTemplateSource('<f:be.infobox title="{error.title}" state="2">{error.message}</f:be.infobox>');
                     return $view->render();
                 }
             }
         }
     }
     return null;
 }

如果您想在預覽中獲得更多高級功能,則必須擴展此方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM