How To Load Email Template By Template ID In Magento 2

Method to load Email template by template ID in Magento 2

To load the Email template by template Id paste the following code.

<?php
namespace VendorName\ModuleName\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Email\Model\Template as coreTemplate;
class Data extends AbstractHelper
{
protected $template;
public function __construct(
Context $context,
coreTemplate $template
)
{
$this->template = $template;
parent::__construct($context);
}
public function templateText($templateId)
{
if (is_numeric($templateId)) {
$this->template->load($templateId);
} else {
$this->template->setForcedArea($templateId);
$this->template->loadDefault($templateId);
}
// another method 
if (is_numeric($templateId)){
$template = $this->template->load($templateId, 'template_id');
}else {
$template = $this->template->load($templateId, 'template_code');
}
$templateText = $this->template->getTemplateText();
return $templateText;
}
}
If you are looking for Magento Developers, visit Magento Developer Agency.
Related Products