How do we get default placeholder image url in template file in magento 2

How do we get default placeholder image url in template file in magento 2

Hi guys,

Today we are going to see how we can get the default placeholder image url in magento 2. There comes many situation where we need to get the default placeholder image of the product. So below is how we can achieve that.

If you check your store settings you will find option of Product Image place holders, you can change your default placeholder from there.

Stores > Configuration > Catalog > Catalog > Product Image Placeholders

The better approach for achieving this would be calling a function on the template file which is defined on your block and performing the operation on that block file. We can simply do that as follows:

On you block file add the code:

 

Now in your template file call:

 

That’s it. Above mentioned approach is the best way of getting the image URL, however you can also do it the dirty way i.e using object manager. In this method you don’t have to use the dependency injection method on the constructor, All the classes could be instantiated on the template file.

Hope this will help.