Mailchimp plugin: support Mailchimp templates and structured HTML templates #142

Open
opened 2026-06-21 16:11:59 +00:00 by jmiller · 0 comments
Owner

Summary

The current Mailchimp plugin sends raw HTML as campaign content via the campaigns/{id}/content endpoint using html directly. It should support:

  1. Mailchimp templates — Use a saved Mailchimp template by ID and inject article content into template sections
  2. Structured plugin template — A built-in HTML email template with proper email layout (header, body, footer, unsubscribe) when no Mailchimp template is specified

Current behavior

MailchimpService.php line 105:

$contentData = json_encode(['html' => $message]);

This sends the raw cross-post message as the entire email HTML — no email wrapper, no header/footer, no unsubscribe link, no responsive design.

Proposed changes

1. Mailchimp template support

Add a template_id credential/config field. When set, use the Mailchimp API's template content injection:

// Instead of raw HTML:
$contentData = json_encode([
    'template' => [
        'id' => (int) $templateId,
        'sections' => [
            'body_content' => $message,  // Inject article into template section
        ],
    ],
]);

The Mailchimp API endpoint PUT /campaigns/{id}/content supports both html (raw) and template (template-based) modes.

2. List available templates

Add a helper method or AJAX endpoint to fetch the user's Mailchimp templates:

GET https://{dc}.api.mailchimp.com/3.0/templates?type=user

This could populate a dropdown in the service edit form.

3. Built-in structured template (fallback)

When no Mailchimp template ID is configured, wrap the content in a proper responsive email HTML template:

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width"></head>
<body style="margin:0;padding:0;background:#f4f4f4;">
  <table width="100%" cellpadding="0" cellspacing="0">
    <tr><td align="center">
      <table width="600" cellpadding="20" style="background:#ffffff;">
        <tr><td>
          <!-- Article content injected here -->
          {content}
        </td></tr>
      </table>
    </td></tr>
  </table>
</body>
</html>

4. Full article content support

The $message parameter currently receives the rendered MokoSuiteCross template (e.g., {title}\n{introtext}\n{url}). For Mailchimp, the default template in install.mysql.sql already uses HTML:

<h1>{title}</h1>\n<p>{introtext}</p>\n<p><a href=\"{url}\">Read more</a></p>

This should be enhanced to optionally include {fulltext} for sending full article content:

<h1>{title}</h1>{fulltext}<p><a href="{url}">Read the original article</a></p>

New config/credential fields

Add to mailchimp.xml:

<field name="template_id" type="text"
    label="PLG_MOKOSUITECROSS_MAILCHIMP_TEMPLATE_ID"
    description="PLG_MOKOSUITECROSS_MAILCHIMP_TEMPLATE_ID_DESC"
    hint="Leave empty for built-in template" />

<field name="template_section" type="text"
    label="PLG_MOKOSUITECROSS_MAILCHIMP_TEMPLATE_SECTION"
    description="PLG_MOKOSUITECROSS_MAILCHIMP_TEMPLATE_SECTION_DESC"
    default="body_content"
    showon="template_id!:" />

<field name="use_full_article" type="radio"
    label="PLG_MOKOSUITECROSS_MAILCHIMP_USE_FULL_ARTICLE"
    description="PLG_MOKOSUITECROSS_MAILCHIMP_USE_FULL_ARTICLE_DESC"
    default="0" class="btn-group btn-group-yesno">
    <option value="0">JNO</option>
    <option value="1">JYES</option>
</field>

Files to modify

  • source/packages/plg_mokosuitecross_mailchimp/src/Extension/MailchimpService.php — template logic in publish()
  • source/packages/plg_mokosuitecross_mailchimp/mailchimp.xml — new config fields
  • source/packages/plg_mokosuitecross_mailchimp/language/en-GB/*.ini — new language strings

Acceptance Criteria

  • When template_id is set, campaign uses Mailchimp template with section injection
  • When template_id is empty, content is wrapped in responsive email HTML
  • use_full_article option passes {fulltext} content to Mailchimp
  • Config fields added to plugin XML with language strings
  • Existing behavior (raw HTML, auto_send toggle) preserved as fallback
## Summary The current Mailchimp plugin sends raw HTML as campaign content via the `campaigns/{id}/content` endpoint using `html` directly. It should support: 1. **Mailchimp templates** — Use a saved Mailchimp template by ID and inject article content into template sections 2. **Structured plugin template** — A built-in HTML email template with proper email layout (header, body, footer, unsubscribe) when no Mailchimp template is specified ## Current behavior `MailchimpService.php` line 105: ```php $contentData = json_encode(['html' => $message]); ``` This sends the raw cross-post message as the entire email HTML — no email wrapper, no header/footer, no unsubscribe link, no responsive design. ## Proposed changes ### 1. Mailchimp template support Add a `template_id` credential/config field. When set, use the Mailchimp API's template content injection: ```php // Instead of raw HTML: $contentData = json_encode([ 'template' => [ 'id' => (int) $templateId, 'sections' => [ 'body_content' => $message, // Inject article into template section ], ], ]); ``` The Mailchimp API endpoint `PUT /campaigns/{id}/content` supports both `html` (raw) and `template` (template-based) modes. ### 2. List available templates Add a helper method or AJAX endpoint to fetch the user's Mailchimp templates: ``` GET https://{dc}.api.mailchimp.com/3.0/templates?type=user ``` This could populate a dropdown in the service edit form. ### 3. Built-in structured template (fallback) When no Mailchimp template ID is configured, wrap the content in a proper responsive email HTML template: ```html <!DOCTYPE html> <html> <head><meta charset="utf-8"><meta name="viewport" content="width=device-width"></head> <body style="margin:0;padding:0;background:#f4f4f4;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr><td align="center"> <table width="600" cellpadding="20" style="background:#ffffff;"> <tr><td> <!-- Article content injected here --> {content} </td></tr> </table> </td></tr> </table> </body> </html> ``` ### 4. Full article content support The `$message` parameter currently receives the rendered MokoSuiteCross template (e.g., `{title}\n{introtext}\n{url}`). For Mailchimp, the default template in `install.mysql.sql` already uses HTML: ```html <h1>{title}</h1>\n<p>{introtext}</p>\n<p><a href=\"{url}\">Read more</a></p> ``` This should be enhanced to optionally include `{fulltext}` for sending full article content: ```html <h1>{title}</h1>{fulltext}<p><a href="{url}">Read the original article</a></p> ``` ## New config/credential fields Add to `mailchimp.xml`: ```xml <field name="template_id" type="text" label="PLG_MOKOSUITECROSS_MAILCHIMP_TEMPLATE_ID" description="PLG_MOKOSUITECROSS_MAILCHIMP_TEMPLATE_ID_DESC" hint="Leave empty for built-in template" /> <field name="template_section" type="text" label="PLG_MOKOSUITECROSS_MAILCHIMP_TEMPLATE_SECTION" description="PLG_MOKOSUITECROSS_MAILCHIMP_TEMPLATE_SECTION_DESC" default="body_content" showon="template_id!:" /> <field name="use_full_article" type="radio" label="PLG_MOKOSUITECROSS_MAILCHIMP_USE_FULL_ARTICLE" description="PLG_MOKOSUITECROSS_MAILCHIMP_USE_FULL_ARTICLE_DESC" default="0" class="btn-group btn-group-yesno"> <option value="0">JNO</option> <option value="1">JYES</option> </field> ``` ## Files to modify - `source/packages/plg_mokosuitecross_mailchimp/src/Extension/MailchimpService.php` — template logic in `publish()` - `source/packages/plg_mokosuitecross_mailchimp/mailchimp.xml` — new config fields - `source/packages/plg_mokosuitecross_mailchimp/language/en-GB/*.ini` — new language strings ## Acceptance Criteria - [ ] When `template_id` is set, campaign uses Mailchimp template with section injection - [ ] When `template_id` is empty, content is wrapped in responsive email HTML - [ ] `use_full_article` option passes `{fulltext}` content to Mailchimp - [ ] Config fields added to plugin XML with language strings - [ ] Existing behavior (raw HTML, auto_send toggle) preserved as fallback
Sign in to join this conversation.
No labels
Priority Medium
Type Feature
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MokoConsulting/MokoSuiteCross#142