1

in my case there is a picture inside my module and I want to get that image inside an HTML file (it's an html file for email header), but when I use Magento syntax it doesn't appear, I have got the page blank without the alt attribute displayed, that means it is there but the page still blank

I have tested with a simple link src="https://www.w3schools.com/html/pic_trulli.jpg" it works

but not with this :

src="<?php echo $this->getViewFileUrl('Vendorname_Core::images/pic.png'); ?>"

can anyone help me, please?

update:

my file inside app/design dir to override : vendor/magento/module-email/view/frontend/email/header.html:


<table class="wrapper" width="100%">
    <tr>
        <td class="wrapper-inner" align="center">
            <table class="main" align="center">
                <tr>
                    <td class="header">
                        <img src="<?php echo $this->getViewFileUrl('Mymodule_Email::images/logo.png'); ?>"
                        />
                    </td>
                </tr>
                <tr>
                    <td class="main-content">
                        <!-- Begin Content -->

8
  • make sure you have entered the right path, in above case pic.jpg will be in pub/static/.../Vendorname_Core/pic.png, make to add img directory name if you have putted in sub dir. Commented Oct 1, 2020 at 13:07
  • i have updated the question , even i put it inside a dir it doesn't work , is there any difference to put it in adminhtml area or frontend?
    – coding mv
    Commented Oct 1, 2020 at 13:12
  • I suggest you to echo that URL directly and check for the proper path and correct it accordingly Commented Oct 1, 2020 at 13:13
  • see the update now ! @RizwanKhan
    – coding mv
    Commented Oct 2, 2020 at 12:03
  • you are writing php code in html file. it will never work. Commented Oct 2, 2020 at 12:13

2 Answers 2

2

You can try this way ..

<img src="<?php echo $this->getViewFileUrl('Vendorname_Core::images/image.png'); ?>" />

and image directory like :

Vendorname/Core/view/frontend/web/images/image.png

then run below commands

rm -rf var/di/* generation/* var/cache/* var/log/* var/page_cache/* var/session/* var/view_preprocessed/* pub/static/*

php -dmemory_limit=4G bin/magento setup:static-content:deploy -f

php bin/magento cache:flush

After check your image showing

2
  • it doesn't work bro for me even if i do that , and the same files structure
    – coding mv
    Commented Oct 1, 2020 at 13:34
  • @lovecoding you want to call in phtml file where? and write here phtml file also in question Commented Oct 2, 2020 at 2:31
1

Make sure you have a file inside the web folder of your module

You can refer below example.

Ex. file placed in below path

app/code/Vendorname/Core/view/frontend/web/images/pic.png

Then you can use the

$this->getViewFileUrl('Vendorname_Core::images/pic.png')

if not still not load then you can verify that images is deployed in the pub/static with the same path of your module if it does not then then please run the below command

php bin/magento setup:static-content:deploy

1
  • yes it's loaded inside pub/static with the same path , i don't know why it won't be displayed on the mail , the mail still without header image
    – coding mv
    Commented Oct 1, 2020 at 13: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.