【问题标题】:How to render a Fuid view template without Extbase? I. e an email template by eID如何在没有 Extbase 的情况下渲染流体视图模板?在 eID 的电子邮件模板中
【发布时间】:2014-11-04 12:48:10
【问题描述】:

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

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

【问题讨论】:

    标签: templates view typo3 fluid


    【解决方案1】:

    这是我为渲染模板而编写的一个简单函数。

    /**
     * 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 一起使用。
    • 但如果我不需要 TSFE 和其他重量级的东西,eID 是首选解决方案。在一个请求中渲染两个不同的views 怎么样?
    • 可以使用 StandaloneView 或$this->forward('other') 渲染otherAction()
    • 对,这就是我使用StandaloneView的原因。
    猜你喜欢
    • 2016-07-29
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多