首页 文章

使用Extbase在Typo3中渲染部分TemplateView

提问于
浏览
0

我想通过Ajax在Extbase Controller中延迟加载几个PartialTemplates . 因此,我发现以下脚本仅渲染部分,但它在我的上下文中不起作用:

private function renderPartial($partialName='', $data = array()){
    if($partialName==''){
        throw new \TYPO3\CMS\Extbase\Mvc\Exception\RequiredArgumentMissingException('The Partial name must be defined.', 123456789);
    }
    $this->templateView = $this->objectManager->create('TYPO3\CMS\Fluid\View\TemplateView');
    $res = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/Private/';
    $this->templateView->setLayoutRootPath($res);
    $this->templateView->setPartialRootPath($res . 'Partials/');
    $this->templateView->setRenderingContext($this->objectManager->create('TYPO3\CMS\Fluid\Core\Rendering\RenderingContext'));
    $this->templateView->setControllerContext($this->controllerContext);

    return $this->templateView->renderPartial($partialName, Null, $data);
}

这会导致以下错误: Fatal error: __clone method called on non-object in /var/www/html/typo3_src-7.6.0/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php on line 281

我为此Goolge并发现很多帖子都有同样的问题 . 我该怎么做才能使这个工作 . 使用StandaloneView和setTemplatePathAndFilename()的变通方法很有效 . 是否可以在没有布局/部分的情况下使用Partial?

编辑:
DebugInfo

我添加了一些调试信息和Controller Action ...

public function searchAction(\PCON\Avm\Domain\Model\DemandSearch $demandSearch = NULL) {

    //GlobalSearch
    if($demandSearch != NULL) {
        $searchResult = $this->demandSearchRepository->findDemanded($demandSearch);
        $this->view->assign('searchResult', $searchResult);
    }

    \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->controllerContext);
    $this->templateView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\TemplateView');
    $res = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/Private/';
    $this->templateView->setLayoutRootPath($res);
    $this->templateView->setPartialRootPath($res . 'Partials/');
    $this->templateView->setRenderingContext($this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext'));
    $this->templateView->setControllerContext($this->controllerContext);
    \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->templateView);
    return $this->templateView->renderPartial('Search/SearchForm.html', Null, array('searchResult'=>$searchResult));
}

我不认为这是一个AJAX问题(由PageNum定义) . 如果我在没有AJAX的情况下调用控制器Action,则出现相同的错误...

1 回答

  • 0

    您可以't use renderPartial() oder renderSection() from extbase/php in StandaloneView. It'是一个缺失的功能,可能无法在TYPO3 7.6及更低版本中实现 . 看这个任务:https://forge.typo3.org/issues/54509

    但是,您可以在Fluid中使用partials和sections . 只需分配变量,然后渲染模板即可

    $this->templateView->render();
    

    并在Fluid模板中使用partials和section .

相关问题