首页 文章

TYPO3流体模板用于tcemain钩子

提问于
浏览
0

TYPO3 6.1

我正在为我的extbase扩展编写一个tcemain钩子 . 我已经在“myextension / Classes / Hooks / myTcemainHook.php中包含了这个钩子php文件 . 在这个钩子里,当我在后端保存记录时,我正在操作来自tca的数据 . 而且我正在将操作数据写入某个文本文件 .

目前我在字符串中获取操作数据并将该字符串写入文件,如下所示

public function processDatamap_afterAllOperations(&$pObj){
  //Write content to a file
  $textFileCnt = 'Label: '.'manipulated text content, that needs to write to file';
  $textFileCnt .= 'Labe2: '.'manipulated text content, that needs to write to file';
  $file1 =   \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('fileadmin/printer/printer.txt');
\TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($file1, $textFileCnt);
}

但在这里,我的要求是使用流体模板 . 因此,文件内容必须使用流体模板格式化,然后应写入文件 .

怎么做到这一点?有帮助吗?

1 回答

  • 0

    看一下独立视图:

    http://forge.typo3.org/projects/typo3v4-mvc/wiki/How_to_use_the_Fluid_Standalone_view_to_render_template_based_emails

    1 /**
     2 * @param array $recipient recipient of the email in the format array('recipient@domain.tld' => 'Recipient Name')
     3 * @param array $sender sender of the email in the format array('sender@domain.tld' => 'Sender Name')
     4 * @param string $subject subject of the email
     5 * @param string $templateName template name (UpperCamelCase)
     6 * @param array $variables variables to be passed to the Fluid view
     7 * @return boolean TRUE on success, otherwise false
     8 */
     9 protected function sendTemplateEmail(array $recipient, array $sender, $subject, $templateName, array $variables = array()) {
    10     /** @var \TYPO3\CMS\Fluid\View\StandaloneView $emailView */
    11     $emailView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
    12 
    13     $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
    14     $templateRootPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']);
    15     $templatePathAndFilename = $templateRootPath . 'Email/' . $templateName . '.html';
    16     $emailView->setTemplatePathAndFilename($templatePathAndFilename);
    17     $emailView->assignMultiple($variables);
    18     $emailBody = $emailView->render();
    19 
    20     /** @var $message \TYPO3\CMS\Core\Mail\MailMessage */
    21     $message = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
    22     $message->setTo($recipient)
    23           ->setFrom($sender)
    24           ->setSubject($subject);
    25 
    26     // Possible attachments here
    27     //foreach ($attachments as $attachment) {
    28     //    $message->attach($attachment);
    29     //}
    30 
    31     // Plain text example
    32     $message->setBody($emailBody, 'text/plain');
    33 
    34     // HTML Email
    35     #$message->setBody($emailBody, 'text/html');
    36 
    37     $message->send();
    38     return $message->isSent();
    39 }
    

相关问题