2013-10-16 52 views
0

TYPO3 6.1TYPO3流體模板爲tcemain鉤

我正在爲我的extbase擴展寫一個tcemain鉤子。 我已經在「myextension/Classes/Hooks/myTcemainHook.php。 」中包含了hook php文件在這個鉤子中,我將操作數據保存到後端,文件中。

目前我得到的字符串處理的數據和寫入該字符串文件中像下面

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

看看獨立觀點:

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 } 

+0

我不得不添加此控制器, $ emailView = \ TYPO3 \ CMS \核心\公用\ GeneralUtility之外的工作: :makeInstance( 'TYPO3 \\ \\ CMS流體\\ \\查看StandaloneView');而不是這個 $ emailView = $ this-> objectManager-> get('TYPO3 \\ CMS \\ Fluid \\ View \\ StandaloneView'); –