{"id":908,"date":"2020-04-03T04:45:14","date_gmt":"2020-04-03T04:45:14","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/04\/03\/load-email-template-by-template-id-in-magento-2\/"},"modified":"2025-05-22T14:37:45","modified_gmt":"2025-05-22T09:07:45","slug":"load-email-template-by-template-id-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/load-email-template-by-template-id-in-magento-2\/","title":{"rendered":"How To Load Email Template By Template ID In Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I have posted the solution to&nbsp;<em><strong>load Email template by template ID in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use the below code if you want to send customers an email with a&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/customize-email-templates-in-magento-2\/\">customized email template<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The solution allows to load the default or custom template using the ID and get the template text.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to load Email template by template ID in Magento 2:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace [Vendor]\\[Module]\\Helper;\n\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\Email\\Model\\Template as coreTemplate;\n\nclass Data extends AbstractHelper\n{\n    protected $template;\n\n    public function __construct(\n        Context $context,\n        coreTemplate $template\n    )\n    {\n        $this->template = $template;\n        parent::__construct($context);\n    }\n\n    public function templateText($templateId)\n    {\n        if (is_numeric($templateId)) {\n            $this->template->load($templateId);\n        } else {\n            $this->template->setForcedArea($templateId);\n            $this->template->loadDefault($templateId);\n        }\n\n        \/\/ another method \n            if (is_numeric($templateId)){\n                $template = $this->template->load($templateId, 'template_id');\n            }else {\n                $template = $this->template->load($templateId, 'template_code');\n            }\n\n        $templateText = $this->template->getTemplateText();\n        return $templateText;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create object of Helper Class and call the function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it. You can also&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/get-store-name-in-magento-2-email-template\/\">get store name in Magento 2 email template<\/a>&nbsp;to enhance your brand consistency, build trust with customers and also adds professional touch to your communication.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I request the readers to share the above solution with the Magento community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have posted the solution to&nbsp;load Email template by template ID in Magento 2. You can use the below code if you want to send&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-908","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=908"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/908\/revisions"}],"predecessor-version":[{"id":14991,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/908\/revisions\/14991"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}