2014-09-10 57 views

回答

3

这是我写的一个简单的函数来呈现我的模板。

/** 
* Renders the fluid email template 
* @param string $template 
* @param array $assign 
* @return string 
*/ 
public function renderFluidTemplate($template, Array $assign = array()) { 
    $templatePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:myextension/Resources/Private/Templates/' . $template); 

    $view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView'); 
    $view->setTemplatePathAndFilename($templatePath); 
    $view->assignMultiple($assign); 

    return $view->render(); 
} 

echo renderFluidTemplate('mail.html', array('test' => 'This is a test!')); 

而且在typo3conf流体模板/转/ MyTemplate的/资源/个人/模板/ mail.html可能看起来像:

Hello 
{test} 

随着输出

Hello 
This is a test! 

你需要布局和部分?

/** 
* Returns the rendered fluid email template 
* @param string $template 
* @param array $assign 
* @param string $ressourcePath 
* @return string 
*/ 
public function renderFluidTemplate($template, Array $assign = array(), $ressourcePath = NULL) { 
    $ressourcePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($ressourcePath === NULL ? 'EXT:myextension/Resources/Private/' : $ressourcePath); 

    /* @var $view \TYPO3\CMS\Fluid\View\StandaloneView */ 
    $view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView'); 
    $view->setLayoutRootPath($ressourcePath . 'Layouts/'); 
    $view->setPartialRootPath($ressourcePath . 'Partials/'); 
    $view->setTemplatePathAndFilename($ressourcePath . 'Templates/' . $template); 
    $view->assignMultiple($assign); 

    return $view->render(); 
} 
+0

提示:而不是使用'eID' - 使用Extbase与引导的Typo脚本行动专用页面类型。 – biesior 2014-09-11 07:40:08

+0

但如果我不需要TSFE和其他重量级的东西,eID是首选的解决方案。以及如何在一个请求中呈现两个不同的'views'? – Ludwig 2014-09-11 08:16:15

+0

你可以使用StandaloneView或'$ this-> forward('other')'呈现'otherAction()' – biesior 2014-09-11 08:21:25