0

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:

http://magento2/media/catalog/product/cache/e616f7b3fa3ef730e13c0a1681a4995e/firt-letter/second-letter/hover_image.jpg

How can I do that? thanks.

1 Answer 1

1

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

in view.xml

<image id="my_id" type="hover_image">
    <width>xxx</width>
    <height>xxx</height>
</image>

in list.phtml

 $_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
 $productImg = $_imagehelper->init($_product,'my_id')->constrainOnly(FALSE)-
 >keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(xxx)->getUrl();

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.