如何在没有Extbase的情况下呈现Fuid视图模板?即通过eID的电子邮件模板 [英] How to render a Fuid view template without Extbase? I. e an email template by eID

查看:103
本文介绍了如何在没有Extbase的情况下呈现Fuid视图模板?即通过eID的电子邮件模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Fluid模板文件通过TYPO3 eID脚本发送电子邮件,以呈现邮件正文.我找不到在普通的MVC Extbase上下文之外如何初始化Fuid View的简单方法.我发现的所有资源似乎都已过时且非常复杂.

I want to send an email by a TYPO3 eID script using a Fluid template file to render the mail body. I could not find a simple way how to initialize a Fuid View outside of the normal MVC Extbase context. All sources I found seemed to be outdated and very complex.

那么渲染流体模板需要什么?

So what is needed to render a fluid template?

推荐答案

这是我编写的用于渲染模板的简单函数.

Here is a simple function I wrote to render my templates.

/**
 * 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 中的流畅模板可能看起来像这样:

And the fluid template in typo3conf/ext/mytemplate/Resources/Private/Templates/mail.html could look like that:

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();
}

这篇关于如何在没有Extbase的情况下呈现Fuid视图模板?即通过eID的电子邮件模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆