Skip to content

Latest commit

 

History

History
80 lines (63 loc) · 1.78 KB

003_decorator.md

File metadata and controls

80 lines (63 loc) · 1.78 KB

Decorating emails

A decorator allows you to set CSS values in the template

By default the NSWDPC\StructuredEmail\Decorator class is used but you can provide your own decorator

<?php
namespace Some\Project;

use NSWDPC\StructuredEmail\AbstractDecorator;

class MyDecorator extends AbstractDecorator {
    
    /**
     * @var string
     */
    private static $type = 'basic';

    /**
     * @var array
     */
    private static $decorations = [
        'FontFamily' => "'Font',Arial,sans-serif",
        'FontSize' => '1em',
        'BodyBackgroundColor' => '#eeeeee',
        'BackgroundColor' => '#ffffff',
        'Color' => '#222555',
        'SubColor' => '#555555',
        'HeadingColor' => '#010101',
        'PrimaryColor' => '#5500ff',
        'PrimaryTextColor' => '#ffffff',
        'HighlightColor' => '#aa55ff',
        'SecondaryColor' => '#e0b9ff'
    ];
}

Then create it:

<?php
$decorator = new MyDecorator();
$email->setDecorator($decorator)->send();

You can also inject your own decorator over NSWDPC\StructuredEmail\Decorator

---
Name: 'project-emails'
---
SilverStripe\Core\Injector\Injector:
  NSWDPC\StructuredEmail\Decorator:
    class: Some\Project\MyDecorator
<?php
use NSWDPC\StructuredEmail\Decorator;
use SilverStripe\Core\Injector\Injector;

$decorator = Injector::inst()->create(Decorator::class);
print get_class($decorator);
// Some\Project\MyDecorator

Set the layout type

A layout type allows you some control over the HTML width (more)

  • basic-full = full width
  • basic = single centred column
  • plain = similar to basic but less decorations
<?php
$decorator->setLayoutType('basic-full');
$email->setDecorator($decorator)->send();