0
votes

TYPO3 6.1

I am writing a tcemain hook for my extbase extension. I have included that hook php file in "myextension/Classes/Hooks/myTcemainHook.php. In this hook, I am manipulating datas coming from tca when save the record in backend. And I am writing that manipulated data to some text file.

Currently I am getting manipulated data in string and writing that string to file like below

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

But here my requirement is to use fluid template for this. So the file content have to be formatted using fluid template and then should write to file.

How to achieve this? Any help?

1

1 Answers

0
votes

Take a look at the standalone view:

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('[email protected]' => 'Recipient Name')
 3 * @param array $sender sender of the email in the format array('[email protected]' => '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 }