PHP code example of goldnead / statamic-email-templates

1. Go to this page and download the library: Download goldnead/statamic-email-templates library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

goldnead / statamic-email-templates example snippets


use Goldnead\EmailTemplates\Facades\EmailTemplates;

$template = EmailTemplates::resolve('welcome');

$template?->subject;    // string, merge tags not yet substituted
$template?->body;       // email-ready HTML
$template?->plain_text; // string|null

$template = EmailTemplates::resolve($slug, function (string $slug) {
    return ['title' => '…', 'body' => '<p>…</p>']; // or null
});

use Goldnead\EmailTemplates\Support\MergeVariables;

// The body is HTML: values are escaped.
$html = MergeVariables::apply($template->body, $data);

// The subject is not HTML: ask for raw output, or the reader sees `&amp;`.
$subject = MergeVariables::apply($template->subject, $data, escape: false);

  $html = MergeVariables::apply($template->body, $data, raw: ['order.lines']);
  

private const SNAPSHOTS = 'Goldnead\\EmailTemplates\\Snapshots\\Snapshots';

// At send time, once — with the template, not with one recipient's mail.
if (class_exists(self::SNAPSHOTS)) {
    $class = self::SNAPSHOTS;

    $snapshot = $class::record('marketing:campaign', $campaign->id, [
        'subject' => $campaign->subject,
        'body' => $templateHtml,
        'slug' => $campaign->templateHandle,
    ]);
}

// On the detail page — an iframe and nothing else.
$url = $class::previewUrl($snapshot);

use Goldnead\EmailTemplates\Contracts\EmailTemplateSource;

$this->app->tag([MySource::class], 'email-templates.sources');

if (app()->bound('email-templates.registry')) {
    app('email-templates.registry')->register([
        'slug' => 'teams-invitation',              // what the addon resolves
        'addon' => 'Teams',                        // who sends it
        'trigger' => fn () => __('teams::mail.invitation.trigger'), // on which occasion
        'event' => \Goldnead\Teams\Events\InvitationSent::class,    // optional
        'placeholders' => [
            'team.name' => ['label' => 'Name of the team', 'example' => 'Sopranos'],
            'url' => 'Link to accept the invitation',
        ],
        'defaults' => fn () => [
            'title' => 'Team invitation',
            'subject' => 'Join {{ team.name }}',
            'preview' => '…',
            'body' => '<p>…<a href="{{ url }}">Accept</a></p>',
        ],
    ]);
}

php artisan vendor:publish --tag=email-templates-config

{{ countdown until="2026-10-01 18:00" }}
→ noch 3 Tage, 4 Stunden (01.10.2026, 18:00 Uhr)

{{ countdown_image until="2026-10-01 18:00" width="480" label="Bis zum Kursstart" }}