Render using custom template on preview
This commit is contained in:
@@ -51,8 +51,7 @@ class Renderer {
|
||||
|
||||
$templateStyles = file_get_contents(dirname(__FILE__) . '/' . self::TEMPLATE_STYLES_FILE);
|
||||
$templateStyles = apply_filters('mailpoet_email_renderer_styles', $templateStyles, $post);
|
||||
// @todo use custom template to render.
|
||||
$templateHtml = $this->contentRenderer->render($post, $this->templates->getBlockTemplateFromFile('email-general.html'));
|
||||
$templateHtml = $this->contentRenderer->render($post, $this->templates->getBlockTemplate('mailpoet/mailpoet//email-general'));
|
||||
|
||||
ob_start();
|
||||
include self::TEMPLATE_FILE;
|
||||
|
@@ -23,23 +23,23 @@ class Templates {
|
||||
add_filter('get_block_template', [$this, 'addBlockTemplateDetails'], 10, 1);
|
||||
}
|
||||
|
||||
public function getBlockFileTemplate($template, $id, $template_type) {
|
||||
$template_name_parts = explode('//', $id);
|
||||
public function getBlockFileTemplate($return, $templateId, $template_type) {
|
||||
$template_name_parts = explode('//', $templateId);
|
||||
|
||||
if (count($template_name_parts) < 2) {
|
||||
return $template;
|
||||
return $return;
|
||||
}
|
||||
|
||||
list( $template_id, $template_slug ) = $template_name_parts;
|
||||
list( $templatePrefix, $templateSlug ) = $template_name_parts;
|
||||
|
||||
if ($this->pluginSlug !== $template_id) {
|
||||
return $template;
|
||||
if ($this->pluginSlug !== $templatePrefix) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
$templatePath = $template_slug . '.html';
|
||||
$templatePath = $templateSlug . '.html';
|
||||
|
||||
if (!is_readable($this->templateDirectory . $templatePath)) {
|
||||
return $template;
|
||||
return $return;
|
||||
}
|
||||
|
||||
return $this->getBlockTemplateFromFile($templatePath);
|
||||
@@ -88,14 +88,23 @@ class Templates {
|
||||
return $block_template;
|
||||
}
|
||||
|
||||
private function getBlockTemplates() {
|
||||
public function getBlockTemplate($templateId) {
|
||||
$templates = $this->getBlockTemplates();
|
||||
return $templates[$templateId] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets block templates indexed by ID.
|
||||
*/
|
||||
public function getBlockTemplates() {
|
||||
$file_templates = [
|
||||
$this->getBlockTemplateFromFile('email-general.html'),
|
||||
];
|
||||
$custom_templates = $this->getCustomBlockTemplates();
|
||||
$custom_template_ids = wp_list_pluck($custom_templates, 'id');
|
||||
|
||||
return array_merge(
|
||||
return array_column(
|
||||
array_merge(
|
||||
$custom_templates,
|
||||
array_filter(
|
||||
$file_templates,
|
||||
@@ -103,6 +112,9 @@ class Templates {
|
||||
return !in_array($blockTemplate->id, $custom_template_ids, true);
|
||||
}
|
||||
),
|
||||
),
|
||||
null,
|
||||
'id'
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user