I want to lazy load several PartialTemplates in an Extbase Controller via Ajax. Therefore I found the following script to render only a Partials but it doesn't work in my context:
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);
}
This results in the following Error: 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
I Goolge for this and found many posts having the same problem. What can I do to make this working. A workaround using the StandaloneView and setTemplatePathAndFilename() works well. Is it possible to use Partial without a Layout/Section?
I added some debug Informations and the 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));
}
I do not think that this is a AJAX Problem (definded by PageNum). If I call the controller Action without AJAX the same error appears ...
