0

I want to access image from a Block in my custom module. This is my current code:

public function getCustomtxt()
{
   $block->getViewFileUrl('images/Phone.jpg');
}
  • please Explain More What do you want ? – Divyesh May 9 '18 at 5:59
  • I Created new Module. the image is stored in view\frontend\web\images\. I want to access the image in the block in my module – Prakash Raj May 9 '18 at 6:02
  • Hey use $this instade of $block. – Divyesh May 9 '18 at 6:09
1
<img src="<?php echo $this->getViewFileUrl('images/Phone.jpg');?>" />
| improve this answer | |
  • Parse error: syntax error, unexpected '<' – Prakash Raj May 9 '18 at 6:27
0

Use below code to display image from image URL.

<img src="<?php echo $this->getViewFileUrl('images/footer-logo.png'); ?>" />
| improve this answer | |
0

Change to below code

Use $this instead $block

<?php echo $this->getViewFileUrl('images/Phone.jpg');?>
| improve this answer | |
  • It displays URL of the image file. Not Displaying the image – Prakash Raj May 9 '18 at 6:12
  • @PrakashRaj Please check my answer – Kishan Patadia May 9 '18 at 6:13
  • @PrakashRaj put this statement in img's src tag , like <img src="myanswer"> – Murtuza Zabuawala May 9 '18 at 6:23

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.