strack/email_templates

Utility package to parse templates for emails easily

1.0.2 2018-06-13 10:03 UTC

This package is not auto-updated.

Last update: 2025-03-01 18:45:50 UTC


README

Simple class for parsing email templates written in HTML with variable data.

Installation

via Composer

Note: This package is not registered on packagist.org.

$ 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.

Use subject instead of title for your email subject in the head section.

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.

<!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.

$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:

$emailTemplate = new EmailTemplate('resource://Acme.Demo/Private/Email/Template/FooBar.html', array(...));