2

Can anyone help me how to include Pub/medial url in email templates in magento2.

Thanks

2

You should use below code:

<img src="{{media url=test/logo.svg}}" alt="" />
1

It should be the same as CMS block logic

So something like this

https://magento.stackexchange.com/a/94907/70343

But you can also add from extension. That might be a cleaner option? Something like this

Package/Modulename/view/frontend/web/images/customimg.png

<img src="{{view url='Package_Modulename/images/customimg.png'}}" height="30" width="30" alt="{{trans 'Custom image'}}" />

1

You can pass Url in setTemplateVars() like below,

public function __construct(
\Magento\Framework\Filesystem\DirectoryList $directory
){
    $this->directory = $directory;
}

You can get Media Url from below code,

$imageUrl  =  $this->directory->getPath('media');

Than after, you can pass in setTemplateVars() like shown below

$templateVars = array(
                        'imageUrl'   => $imageUrl
                    );

You can use in your template file like this

{{var imageUrl}}

Hope it helps.

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.