【发布时间】:2014-11-04 12:48:10
【问题描述】:
我想使用 Fluid 模板文件通过 TYPO3 eID 脚本发送电子邮件以呈现邮件正文。我找不到一种简单的方法来在正常的 MVC Extbase 上下文之外初始化一个 Fuid 视图。我发现的所有来源似乎都已过时且非常复杂。
那么渲染流体模板需要什么?
【问题讨论】:
标签: templates view typo3 fluid
我想使用 Fluid 模板文件通过 TYPO3 eID 脚本发送电子邮件以呈现邮件正文。我找不到一种简单的方法来在正常的 MVC Extbase 上下文之外初始化一个 Fuid 视图。我发现的所有来源似乎都已过时且非常复杂。
那么渲染流体模板需要什么?
【问题讨论】:
标签: templates view typo3 fluid
这是我为渲染模板而编写的一个简单函数。
/**
* 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/ext/mytemplate/Resources/Private/Templates/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();
}
【讨论】:
eID - 在具有专用页面类型的 TypoScript 中将 Extbase 的操作与 Bootstrap 一起使用。
views 怎么样?
$this->forward('other') 渲染otherAction()
StandaloneView的原因。