TYPO3流体:自TYPO3 4.6起,使用自己的流体渲染器失败

时间:2012-01-04 17:12:36

标签: typo3 fluid extbase

我在扩展中使用了自己的流体渲染器:

/**
 * Makes and returns a fluid template object
 *
 * @return Tx_Fluid_View_TemplateView the fluid template object
 */
protected function makeFluidTemplateObject() {
    /** @var Tx_Fluid_View_TemplateView $fluidTemplate  */
    $fluidTemplate = t3lib_div::makeInstance('Tx_Fluid_View_TemplateView');

    // Set controller context
    $controllerContext = $this->buildControllerContext();
    $controllerContext->setRequest($this->request);
    $fluidTemplate->setControllerContext($controllerContext);

    return $fluidTemplate;
}

我稍后使用此$fluidTemplate分配模板文件,变量并呈现它:

/**
 * Gets the mail message
 *
 * @param mixed $registration model to give to template
 * @param string $templatePath path of fluid template
 *
 * @return string The rendered fluid template (HTML or plain text)
 */
public function getMailMessage($registration, $templatePath) {
    $mailTemplate = t3lib_div::getFileAbsFileName($templatePath);
    if (!file_exists($mailTemplate)) {
        throw new Exception('Mail template (' . $mailTemplate . ') not found. ');
    }
    $this->fluidTemplate->setTemplatePathAndFilename($mailTemplate);

    // Assign variables
    $this->fluidTemplate->assign('registration', $registration);
    $this->fluidTemplate->assign('settings', $this->settings);

    return $this->fluidTemplate->render();
}

->render()电话外,一切正常。我收到错误500而没有任何指定的异常,因为TYPO3 4.6。使用TYPO3 4.5 LTS它正在工作!

我希望有人有个主意。提前谢谢!

1 个答案:

答案 0 :(得分:1)

从TYPO3 v4.6开始,您不再需要构建整个控制器上下文了。它现在通过Tx_Fluid_View_StandaloneView(Fluid 1.4.0)处理

初始化视图:

protected function makeFluidTemplateObject() {
    $this->fluidTemplate = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView');
    return $this->fluidTemplate;
}

函数getMailMessage($registration, $templatePath)保持不变。