2

how can i send company logo in custom email templates ? I know that it is placed on header.html in vendor/magento/module-email/view/frontend/email

2

1 Answer 1

2

EDIT: We can use block technique. And put it where you want. For example, insert this block in your template:

{{block class='Company\\Module\\Block\\Email\\Logo' 
area='frontend' template='Company_Module::email/logo.phtml'}}

Your custom block:

<?php

namespace Company\Module\Block\Email;

use Magento\Framework\View\Element\Template;

class Logo extends \Magento\Framework\View\Element\Template
{
    protected $logo;

    public function __construct(
        Template\Context $context,
        \Magento\Theme\Block\Html\Header\Logo $logo,
        array $data = []
    )
    {
        $this->logo = $logo;
        parent::__construct($context, $data);
    }

    /**
     * Get logo image URL
     *
     * @return string
     */
    public function getLogoSrc()
    {
        return $this->logo->getLogoSrc();
    }

}

Template: view/templates/email/logo.phtml

<?php
/** @var $block \Company\Module\Block\Email\Logo */
/** @var $this  \Company\Module\Block\Email\Logo*/
?>

<img src="<?php echo $this->getLogoSrc()?>" alt="<?php echo __('Logo Image'); ?>"/>

See more here: vendor/magento/module-sales/view/frontend/email/shipment_new.html

7
  • In header.html ? Commented Sep 16, 2016 at 9:59
  • Anywhere you want. Commented Sep 16, 2016 at 10:00
  • It's not working :( i put this header.html which included in my custom email template ? Commented Sep 16, 2016 at 10:11
  • 1
    Try <img src="{{view url='Magento_Email/logo_email.png'}}" height="30" width="30" alt="{{trans 'Logo'}}" />. Commented Sep 16, 2016 at 10:21
  • Should i move header.html file and less files (email-inline.less and email.less) in my theme folder under module-email folder ? Commented Sep 16, 2016 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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