1

I am working on one custom module and I need to fetch the transactional email templates grid which is at Marketing > email templates in magento 2 default. I need that grid in my custom extension, how can i get that?


enter image description here

0

First you will have to inject the Magento\Email\Model\ResourceModel\Template\CollectionFactory class in your constructor:

protected $emailTemplateCollectionFactory;


public function __construct(
        ...
        \Magento\Email\Model\ResourceModel\Template\CollectionFactory $emailTemplateCollectionFactory
) {
        ...
        $this->emailTemplateCollectionFactory= $emailTemplateCollectionFactory;
        ...

}

Then you can create the collection by calling:

$collection = $this->emailTemplateCollectionFactory->create();
6
  • This seems to be working, but how can I get the id and title of the email template in separate array? Thank you in advance, Jun 21 '16 at 9:00
  • @GauravJain when you loop through your collection you can call ->getTemplateId() to get the id and ->getTemplateCode to get the title Jun 21 '16 at 9:05
  • Can you provide the sample code for foreach loop? Because when we try foreach loop, it only prints first record data. If print whole collection then only it shows all records in log but not in foreach loop. Jun 21 '16 at 9:29
  • @GauravJain you can do foreach ($collection as $template) { $id = $template->getTemplateId(); $title = $template->getTemplateCode(); } Jun 21 '16 at 9:33
  • Thanks for the code, I am trying the code but it is giving me blank data in log file. Jun 21 '16 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.