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);
}
但是我的要求是使用流体模板。 因此,必须使用流体模板格式化文件内容,然后写入文件。
如何实现这一目标?有什么帮助吗?
答案 0 :(得分:0)
查看独立视图:
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 }