I have custom media attribute for hover hover_image I would like from list.phtml to get this full path url to cached file.

e.g small_image image in list.phtml is: http://magento2/media/catalog/product/cache/e616f7b3fa3ef730e13c0a1681a4995e/b/l/test.jpg

I need hover_image e.g:


How can I do that? thanks.


I've got this. So this is quite simple:

in view.xml

<image id="my_id" type="hover_image">

in list.phtml

 $_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
 $productImg = $_imagehelper->init($_product,'my_id')->constrainOnly(FALSE)-

Note: keepAspectRatio, keepFrame, resize can be set in xml too instead.

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.