Skip to content

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

Open Setup > Campaigns > Campaign Types (requires campaign-admin) to define reusable email blueprints such as newsletter, welcome, and announcement.

Campaign Types standardize authoring mode, CSS inlining, and automatic plaintext generation across your team.

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 inside site/templates/campaigns/ when authoring_mode is php_template (path traversal such as ../ is strictly rejected).
  • inline_css: Runs EmailCssInliner over <style> blocks to produce email-client-safe inline style="" attributes.
  • auto_plaintext: Automatically derives a clean plain-text MIME part via HtmlToPlainText whenever 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}}.
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.

Navigate to Setup > Campaigns > Campaigns to list, filter, search, duplicate, and edit campaigns.

The Campaigns index supports saved filter views, table/card layouts, search, and quick row actions.

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.

Each campaign supports multi-language subject, preheader, and body fields plus instant Preview and Send Test actions.

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')}} renders Guest when 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:

  1. Content assembly: Resolves rich_text, php_template, blocks, or raw_html.
  2. Merge interpolation: Evaluates {{variable}}, {{#if}}, and link shortcodes.
  3. Relative image absolutization: Rewrites root-relative <img src="/site/assets/..."> URLs to full https:// URLs using site_base_url (or $config->httpHost) so external email clients load images reliably.
  4. CSS inlining: Applies EmailCssInliner when enabled on the Campaign Type.
  5. UTM enrichment & click tracking: Appends configured utm_source, utm_medium, utm_campaign, utm_content, and utm_term parameters, then rewrites http(s) links through /_campaign/c/{token} when click tracking is enabled.
  6. Open pixel & plaintext: Injects the 1x1 GIF open pixel (/_campaign/o/{token}.gif) if open tracking is enabled and generates the plain-text part via HtmlToPlainText.
  7. Hooks: Fires Campaign::afterRender and Campaign::beforeSend, allowing developers to inspect or modify the RenderedEmail value object.

Place PHP templates under site/templates/campaigns/ and reference the filename (for example, aegean-launch.php) in your Campaign Type:

<?php
declare(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. CampaignDispatcher attaches them to the outgoing WireMail message.
  • 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.

Next steps