🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How To Load Email Template By Template ID In Magento 2

By Sanjay JethvaUpdated on May 22, 2025 1 min read

I have posted the solution to load Email template by template ID in Magento 2.

You can use the below code if you want to send customers an email with a customized email template.

The solution allows to load the default or custom template using the ID and get the template text.

Method to load Email template by template ID in Magento 2:

<?php

namespace [Vendor]\[Module]\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;
    }
}

Create object of Helper Class and call the function.

That’s it. You can also get store name in Magento 2 email template to enhance your brand consistency, build trust with customers and also adds professional touch to your communication.

I request the readers to share the above solution with the Magento community via social media.

Thank you.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.