0
votes

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?

EDIT: DebugInfo

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 ...

1
Well, you should debug your approach, it's hard to guess what have you done (how did you initialize your AJAX action... have it proper Extbase's context?) On the other hand StandaloneView is natural candidate for rendering ... standalone parts views/partials etc. - biesior
hi, thx for the fast response. I added some additional informations. I don't think that this is an ajax problem... - Jürgen Pfusterschmied

1 Answers

0
votes

You can't use renderPartial() oder renderSection() from extbase/php in StandaloneView. It's a missing feature that will probably not be implemented in TYPO3 7.6 and below. See this task: https://forge.typo3.org/issues/54509

However, you can use partials and sections in Fluid. Just assign your variables, then render your template with

$this->templateView->render();

And use partials and section in your Fluid template.