MKcom.Utility.EmailTemplates
Simple class for parsing email templates written in HTML with variable data., (*1)
Installation
via Composer
Note: This package is not registered on packagist.org., (*2)
$ composer config repositories.mkcom/utility-emailtemplates vcs git@github.com:mkeitsch/utility-emailtemplates.git
$ composer require mkcom/utility-emailtemplates
Using EmailTemplates
Create a simple HTML file for an email template., (*3)
Use subject instead of title for your email subject in the head section., (*4)
Double curly braces {{}} are used for defining variables. You can use it wherever you want in the template. I recommend using camelCased variable names. These are tested. But you can use and test whatever you want., (*5)
<!DOCTYPE html>
<html>
<head>
<subject>
My Subject For A New Email
</subject>
</head>
<body>
Hey {{firstName}},
this is a my email template.
Greetings {{senderName}} :)
</body>
</html>
Create a new email template by just instantiating the EmailTemplate class with the location of the template file and an array of variables that should be inserted as arguments., (*6)
$emailTemplate = new EmailTemplate(__DIR__.'/Templates/myEmailTemplate.html', array(
'firstName' => 'John',
'senderName' => 'Max',
));
$emailBody = $emailTemplate->getBody();
$emailSubject = $emailTemplate->getSubject();
Perfect Neos Flow Integration
Works perfectly with Neos Flow and the resource://-Wrapper:, (*7)
$emailTemplate = new EmailTemplate('resource://Acme.Demo/Private/Email/Template/FooBar.html', array(...));