Magento 2: Get image url in template file


Step 1) Put your image on Your Magento 2 Path: /app/design/frontend/< Vendor >/< theme >/web/images

Step 2) Use this code to call the image in phtml file

<?php echo $block->getViewFileUrl('images/demo.jpg'); ?>
Advertisements

5 thoughts on “Magento 2: Get image url in template file

  1. Thanks, this helped me. In case anyone else is wondering. If you need an asset of a specifc module, you can prefix it with ‘::’.:

    $this->getViewFileUrl(‘Vendor_Module::img/spinner.gif’);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s