Campaigns & Templates
Every email in Campaign pairs a Campaign Type (which controls the authoring mode, layout chrome, CSS inlining, and auto-plaintext rules) with a Campaign entry (which holds the subject, preheader, body content, sender overrides, UTM parameters, and attachments).
Campaign Types (campaign-type)
Section titled “Campaign Types (campaign-type)”Open Setup > Campaigns > Campaign Types (requires campaign-admin) to define reusable email blueprints such as newsletter, welcome, and announcement.
Each Campaign Type configures:
title&handle: Human label and machine handle (for example,newsletter).authoring_mode: One of the four supported rendering pipelines (rich_text,php_template,blocks,raw_html).php_template_file: Confined filename insidesite/templates/campaigns/whenauthoring_modeisphp_template(path traversal such as../is strictly rejected).inline_css: RunsEmailCssInlinerover<style>blocks to produce email-client-safe inlinestyle=""attributes.auto_plaintext: Automatically derives a clean plain-text MIME part viaHtmlToPlainTextwhenever a campaign leaves its manual plaintext field empty.default_layout_wrapper: Optional brand HTML wrapper with{{content}},{{brand_name}},{{brand_accent}},{{unsubscribe_url}}, and{{preferences_url}}.
The 4 Authoring Modes
Section titled “The 4 Authoring Modes”| Mode | Best For | How CampaignRenderer Renders It |
|---|---|---|
rich_text |
Editorial newsletters, announcements, welcome emails | Wraps the rich-text HTML body in the brand layout (logo, accent color, footer) and runs CSS inlining. |
php_template |
Bespoke transactional or seasonal designs | Executes site/templates/campaigns/<file>.php in an isolated scope with $campaign, $contact, $sendout, and $urls variables. |
blocks |
Modular drag-and-drop layouts | Renders a Blocks field via the optional Blocks integration (Campaign::renderBlocksContent hook). |
raw_html |
Hand-coded responsive HTML tables | Sends your exact HTML document verbatim while still resolving merge variables, link wrapping, and optional CSS inlining. |
Authoring Campaigns (campaign)
Section titled “Authoring Campaigns (campaign)”Navigate to Setup > Campaigns > Campaigns to list, filter, search, duplicate, and edit campaigns.
Opening a campaign reveals a five-tab editor (Content, HTML, Plaintext & Blocks, Sender & UTM, Attachments, and Settings) with multi-language tabs (LanguageSupport) and top-bar Preview, Send Test, Duplicate, and Save buttons.
Merge Variables, Conditionals & Shortcodes
Section titled “Merge Variables, Conditionals & Shortcodes”CampaignRenderer evaluates merge tokens in the subject line, preheader, HTML body, and plain-text body for every recipient:
- Contact & Custom Fields:
{{contact.first_name}},{{contact.last_name}},{{contact.full_name}},{{contact.email}},{{contact.company_name}},{{contact.domain_meta.tier}}. - Fallback Filter:
{{contact.first_name | default('Guest')}}rendersGuestwhen the contact has no first name. - Conditionals:
{{#if contact.first_name}} <p>Hello {{contact.first_name}}, your early-access window is open.</p>{{else}} <p>Hello, your early-access window is open.</p>{{/if}}- System Link Shortcodes:
[unsubscribe]or{{unsubscribe_url}}: Signed one-click unsubscribe URL (RFC 8058).[preferences]or{{preferences_url}}: Signed subscriber preference center URL.[view_in_browser]or{{view_in_browser_url}}: Sandboxed web archive URL (/_campaign/view/{token}).
Rendering Pipeline, CSS Inlining & Relative Images
Section titled “Rendering Pipeline, CSS Inlining & Relative Images”Before handing a message to WireMail, CampaignRenderer executes a deterministic pipeline:
- Content assembly: Resolves
rich_text,php_template,blocks, orraw_html. - Merge interpolation: Evaluates
{{variable}},{{#if}}, and link shortcodes. - Relative image absolutization: Rewrites root-relative
<img src="/site/assets/...">URLs to fullhttps://URLs usingsite_base_url(or$config->httpHost) so external email clients load images reliably. - CSS inlining: Applies
EmailCssInlinerwhen enabled on the Campaign Type. - UTM enrichment & click tracking: Appends configured
utm_source,utm_medium,utm_campaign,utm_content, andutm_termparameters, then rewriteshttp(s)links through/_campaign/c/{token}when click tracking is enabled. - Open pixel & plaintext: Injects the
1x1GIF open pixel (/_campaign/o/{token}.gif) if open tracking is enabled and generates the plain-text part viaHtmlToPlainText. - Hooks: Fires
Campaign::afterRenderandCampaign::beforeSend, allowing developers to inspect or modify theRenderedEmailvalue object.
Writing a Confined PHP Email Template
Section titled “Writing a Confined PHP Email Template”Place PHP templates under site/templates/campaigns/ and reference the filename (for example, aegean-launch.php) in your Campaign Type:
<?phpdeclare(strict_types=1);
namespace ProcessWire;
/** * @var \Totoglu\Entries\Entity\EntryItem $campaign * @var \Totoglu\Entries\Entity\EntryItem $contact * @var array<string, string> $urls */$firstName = $sanitizer->entities((string) ($contact->get('first_name') ?: 'Guest'));$subject = $sanitizer->entities((string) $campaign->get('subject'));$unsubscribeUrl = $sanitizer->entities($urls['unsubscribe'] ?? '');?><!doctype html><html lang="en"><head> <meta charset="utf-8"> <title><?= $subject ?></title> <style> body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; color: #1e293b; } .btn { display: inline-block; padding: 12px 20px; background: #0f766e; color: #ffffff; text-decoration: none; border-radius: 6px; } </style></head><body> <h1>Hello <?= $firstName ?>,</h1> <p>Our 2026 Gocek 12 Islands and Dodecanese charter dates are now open for priority booking.</p> <p><a class="btn" href="https://aegean-voyages.example/routes/2026">Explore 2026 Routes</a></p> <p style="font-size:12px;color:#64748b;"> <a href="<?= $unsubscribeUrl ?>">Unsubscribe</a> </p></body></html>File Attachments, Live Preview & Test Sends
Section titled “File Attachments, Live Preview & Test Sends”- Attachments: Upload PDF itineraries, brochures, or ICS calendar files on the Attachments tab.
CampaignDispatcherattaches them to the outgoingWireMailmessage. - Live Preview: Click Preview in the editor toolbar (or Preview on the Overview card) to inspect rendered HTML and plain-text output across desktop and mobile widths without sending email.
- Test Sends: Click Send Test in the editor or call
$campaign->sendTest($campaignEntry, ['[email protected]'])in PHP to verify inbox rendering across mail clients before launching a sendout.