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 = file_get_contents(dirname(__FILE__) . '/' . self::TEMPLATE_STYLES_FILE);
|
||||||
$templateStyles = apply_filters('mailpoet_email_renderer_styles', $templateStyles, $post);
|
$templateStyles = apply_filters('mailpoet_email_renderer_styles', $templateStyles, $post);
|
||||||
// @todo use custom template to render.
|
$templateHtml = $this->contentRenderer->render($post, $this->templates->getBlockTemplate('mailpoet/mailpoet//email-general'));
|
||||||
$templateHtml = $this->contentRenderer->render($post, $this->templates->getBlockTemplateFromFile('email-general.html'));
|
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
include self::TEMPLATE_FILE;
|
include self::TEMPLATE_FILE;
|
||||||
|
@@ -23,23 +23,23 @@ class Templates {
|
|||||||
add_filter('get_block_template', [$this, 'addBlockTemplateDetails'], 10, 1);
|
add_filter('get_block_template', [$this, 'addBlockTemplateDetails'], 10, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockFileTemplate($template, $id, $template_type) {
|
public function getBlockFileTemplate($return, $templateId, $template_type) {
|
||||||
$template_name_parts = explode('//', $id);
|
$template_name_parts = explode('//', $templateId);
|
||||||
|
|
||||||
if (count($template_name_parts) < 2) {
|
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) {
|
if ($this->pluginSlug !== $templatePrefix) {
|
||||||
return $template;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$templatePath = $template_slug . '.html';
|
$templatePath = $templateSlug . '.html';
|
||||||
|
|
||||||
if (!is_readable($this->templateDirectory . $templatePath)) {
|
if (!is_readable($this->templateDirectory . $templatePath)) {
|
||||||
return $template;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getBlockTemplateFromFile($templatePath);
|
return $this->getBlockTemplateFromFile($templatePath);
|
||||||
@@ -88,21 +88,33 @@ class Templates {
|
|||||||
return $block_template;
|
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 = [
|
$file_templates = [
|
||||||
$this->getBlockTemplateFromFile('email-general.html'),
|
$this->getBlockTemplateFromFile('email-general.html'),
|
||||||
];
|
];
|
||||||
$custom_templates = $this->getCustomBlockTemplates();
|
$custom_templates = $this->getCustomBlockTemplates();
|
||||||
$custom_template_ids = wp_list_pluck($custom_templates, 'id');
|
$custom_template_ids = wp_list_pluck($custom_templates, 'id');
|
||||||
|
|
||||||
return array_merge(
|
return array_column(
|
||||||
$custom_templates,
|
array_merge(
|
||||||
array_filter(
|
$custom_templates,
|
||||||
$file_templates,
|
array_filter(
|
||||||
function($blockTemplate) use ($custom_template_ids) {
|
$file_templates,
|
||||||
return !in_array($blockTemplate->id, $custom_template_ids, true);
|
function($blockTemplate) use ($custom_template_ids) {
|
||||||
}
|
return !in_array($blockTemplate->id, $custom_template_ids, true);
|
||||||
|
}
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
null,
|
||||||
|
'id'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user