geno/wp-content/plugins/mailpoet/lib/EmailEditor/Engine/Renderer
2024-02-01 11:54:18 +00:00
..
Preprocessors first commit 2024-02-01 11:54:18 +00:00
BlockRenderer.php first commit 2024-02-01 11:54:18 +00:00
BlocksRegistry.php first commit 2024-02-01 11:54:18 +00:00
index.php first commit 2024-02-01 11:54:18 +00:00
PreprocessManager.php first commit 2024-02-01 11:54:18 +00:00
readme.md first commit 2024-02-01 11:54:18 +00:00
Renderer.php first commit 2024-02-01 11:54:18 +00:00
styles.css first commit 2024-02-01 11:54:18 +00:00
template.html first commit 2024-02-01 11:54:18 +00:00

MailPoet Email Renderer

The renderer is WIP and so is the API for adding support email rendering for new blocks.

Adding support for a core block

  1. Add block into ALLOWED_BLOCK_TYPES in mailpoet/lib/EmailEditor/Engine/Renderer/SettingsController.php.
  2. Make sure the block is registered in the editor. Currently all core blocks are registered in the editor.
  3. Add BlockRender class (e.g. Heading) into mailpoet/lib/EmailEditor/Integration/Core/Renderer/Blocks folder.
<?php declare(strict_types = 1);

namespace MailPoet\EmailEditor\Integrations\Core\Renderer\Blocks;

use MailPoet\EmailEditor\Engine\Renderer\BlockRenderer;
use MailPoet\EmailEditor\Engine\SettingsController;

class Heading implements BlockRenderer {
  public function render($blockContent, array $parsedBlock, SettingsController $settingsController): string {
    return 'HEADING_BLOCK'; // here comes your rendering logic;
  }
}
  1. Register the renderer
<?php

use MailPoet\EmailEditor\Engine\Renderer\BlocksRegistry;

add_action('mailpoet_blocks_renderer_initialized', 'register_my_block_email_renderer');

function register_my_block_email_renderer(BlocksRegistry $blocksRegistry): void {
  $blocksRegistry->addBlockRenderer('core/heading', new Renderer\Blocks\Heading());
}

Note: For core blocks this is currently done in MailPoet\EmailEditor\Integrations\Core\Initializer.

  1. Implement the rendering logic in the renderer class.

Tips for adding support for block

  • You can take inspiration on block rendering from MJML in the https://mjml.io/try-it-live
  • Test the block in different clients Litmus
  • You can take some inspirations from the HTML renderer by the old email editor

TODO

  • add universal/fallback renderer for rendering blocks that are not covered by specialized renderers
  • add support for all core blocks
  • move the renderer to separate package