If you just want to get your custom templates you added in the backend, you can use Magento\Email\Model\ResourceModel\Template\CollectionFactory.php
. If you want all email templates from config, you can use Magento\Email\Model\Template\Config.php
namespace Vendor\Module\Helper;
use Magento\Email\Model\ResourceModel\Template\CollectionFactory;
use Magento\Email\Model\Template\Config;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/** @var CollectionFactory */
protected $_collectionFactory;
/** @var Config */
protected $_emailConfig;
/**
* @param \Magento\Framework\App\Helper\Context $context
* @param CollectionFactory $collectionFactory
* @param Config $emailConfig
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
CollectionFactory $collectionFactory,
Config $emailConfig,
array $data = []
)
{
$this->_collectionFactory = $collectionFactory;
$this->_emailConfig = $emailConfig;
parent::__construct($context, $data);
}
/**
* Returns collection of custom templates
*
* @return mixed
*/
public function getCustomTemplates()
{
return $this->_collectionFactory->create();
}
/**
* Returns collection of all available templates
*
* @return array[]
*/
public function getConfigTemplates()
{
return $this->_emailConfig->getAvailableTemplates();
}
}