Files
WooNooW/TEMPLATE_SOURCE_OF_TRUTH.md
dwindown 4471cd600f feat: Complete markdown syntax refinement and variable protection
 New cleaner syntax implemented:
- [card:type] instead of [card type='type']
- [button:style](url)Text[/button] instead of [button url='...' style='...']
- Standard markdown images: ![alt](url)

 Variable protection from markdown parsing:
- Variables with underscores (e.g., {order_items_table}) now protected
- HTML comment placeholders prevent italic/bold parsing
- All variables render correctly in preview

 Button rendering fixes:
- Buttons work in Visual mode inside cards
- Buttons work in Preview mode
- Button clicks prevented in visual editor
- Proper styling for solid and outline buttons

 Backward compatibility:
- Old syntax still supported
- No breaking changes

 Bug fixes:
- Fixed order_item_table → order_items_table naming
- Fixed button regex to match across newlines
- Added button/image parsing to parseMarkdownBasics
- Prevented button clicks on .button and .button-outline classes

📚 Documentation:
- NEW_MARKDOWN_SYNTAX.md - Complete user guide
- MARKDOWN_SYNTAX_AND_VARIABLES.md - Technical analysis
2025-11-15 20:05:50 +07:00

3.4 KiB

Template Source of Truth

Single Source of Truth: /includes/Email/DefaultTemplates.php

This file contains clean markdown templates without HTML tags inside shortcodes.

Structure

namespace WooNooW\Email;

class DefaultTemplates {
    public static function get_all_templates() {
        return [
            'customer' => [
                'order_placed' => '...',
                'order_confirmed' => '...',
                'order_shipped' => '...',
                'order_completed' => '...',
                'order_cancelled' => '...',
                'payment_received' => '...',
                'payment_failed' => '...',
                'registered' => '...',
                'vip_upgraded' => '...',
            ],
            'staff' => [
                'order_placed' => '...',
                'order_confirmed' => '...',
                'order_shipped' => '...',
                'order_completed' => '...',
                'order_cancelled' => '...',
                'payment_received' => '...',
                'payment_failed' => '...',
            ],
        ];
    }
    
    public static function get_default_subject($recipient, $event) {
        // Returns subject string
    }
}

Template Format

Templates use clean markdown inside [card] shortcodes:

[card type="hero"]

## Thank you for your order, {customer_name}!

We've received your order and will begin processing it right away.
[/card]

[card]

**Order Number:** #{order_number}
**Order Date:** {order_date}
**Order Total:** {order_total}

[/card]

[button url="{order_url}"]View Order Details[/button]

NOT HTML like this:

[card type="hero"]
<h1>Thank you for your order, {customer_name}!</h1>
<p>We've received your order...</p>
[/card]

How It's Used

TemplateProvider.php

/includes/Core/Notifications/TemplateProvider.php uses the Email templates:

use WooNooW\Email\DefaultTemplates as EmailDefaultTemplates;

// Get all templates
$allEmailTemplates = EmailDefaultTemplates::get_all_templates();

// Get specific template
$body = $allEmailTemplates[$recipient_type][$template_name];
$subject = EmailDefaultTemplates::get_default_subject($recipient_type, $template_name);

Event ID Mapping

API event IDs are mapped to template names:

API Event ID Template Name
order_processing order_confirmed
new_customer registered
Others Same name

Deprecated Files

/includes/Core/Notifications/DefaultEmailTemplates.php

DO NOT USE - This file contains old templates with HTML tags inside shortcodes.

It's kept for backwards compatibility only and is marked as deprecated.

Frontend Conversion

When templates are loaded in the editor:

  1. Database stores HTML (for backwards compatibility)
  2. converter.ts converts HTML to clean markdown using convertHtmlToMarkdown()
  3. CodeEditor displays clean markdown
  4. User edits in markdown
  5. Saves back as HTML (via blocks → HTML conversion)

This ensures smooth editing experience while maintaining compatibility.

Benefits

Clean markdown editing - No HTML tags in markdown mode Single source of truth - One place to update templates Better UX - Markdown toolbar and syntax highlighting Mobile-friendly - Easy to type on any device Maintainable - Clear separation of concerns