【问题标题】:TYPO3 change template inside action methodTYPO3 在动作方法中更改模板
【发布时间】:2016-08-03 12:44:02
【问题描述】:

在我的分机中,我有 singleAction 方法。我想在此方法中更改模板,因为我有 2 个用于单个操作的模板。是否可以?如果不可能,我该如何解决这个问题?也许会产生另一个动作?

【问题讨论】:

    标签: typo3 typo3-7.6.x


    【解决方案1】:

    设置模板并不是那么简单。 setTemplategetTemplate 在视图中不存在。 您可以恢复为支持使用 setTemplatePathAndFilename

    的独立视图实现

    (从Ludwig复制的示例)

    /**
     * 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!'));
    

    您也可以使用打字稿切换到不同的模板。

    plugin.tx_yourpluginname.view.templateRootPaths = EXT:extension_name/Resources/Private/CustomPath/Templates/
    

    这可以放入任何你想要的打字条件。

    【讨论】:

    • 哈,事实证明你是对的。我在 StandaloneView 的上下文中使用了我的代码。
    【解决方案2】:

    处理这个问题的最佳方法是在动作模板中进行切换,加载不同的部分。这样一来,整个逻辑流程保持不变,并且对于以后必须编辑您的代码的每个人来说都可以立即理解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 2014-02-05
      • 1970-01-01
      • 2013-05-17
      相关资源
      最近更新 更多