How to call mail template in extbase typo3 || How to call template in extbase extension of typo


Below code will guide you for call template in extbase exntesion. for that you just have to set below code in your extension.

$variables['mail'] = array( 'firstname' => "Jainish",
     'lastname' => "Senjaliya",
     'gender' => "Mr.",
    );
									
$emailView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
$templateName = 'Email/mailContact.html';
$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$templateRootPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']);
$templatePathAndFilename = $templateRootPath.$templateName;
$emailView->setTemplatePathAndFilename($templatePathAndFilename);
$emailView->assignMultiple($variables);
$emailBody = $emailView->render();

Note:
$templateName = ‘Email/mailContact.html’;
You have to create Email folder under “Resources/Private/Templates/Email”

and create “mailContact.html” file under Email folder

Content in “mailContact.html” file is :

<f:layout name='Default'/>
<f:section name='main'>

   <f:translate key="LLL:EXT:EXT_NAME/Resources/Private/Language/locallang.xlf:tx_registration_domain_model_registration.dear" /> {mail.gender} {mail.firstname} {mail.lastname},
		
   Welcome to TYPO... 
		
   Thanks,
</f:section>

You can get your label from your locallang file through below syntax

<f:translate key="LLL:EXT:EXT_NAME/Resources/Private/Language/locallang.xlf:tx_registration_domain_model_registration.dear" />

This will get your label from locallang.xlf file. 

You have to given full path for get your label from locallang.xlf file

and then after you have to create “Layouts” folder under “Resources/Private/Templates/Email/Layouts” and create “Default.html” under “Layouts” folder.

Content in “Default.html” file is :

<f:render section='main'/>

After that you will get content in $emailBody is

  Dear Mr. Jainish Senjaliya,
		
  Welcome to TYPO... 
		
  Thanks,

and you can send this content via email. below link will guide for how to send mail in extbase.
How to send mail in extbase typo3 || How to send mail using swiftmailer in extbase typo3

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

One thought on “How to call mail template in extbase typo3 || How to call template in extbase extension of typo

Leave a reply to bhavana Cancel reply