Hi i want to Create custom Featured Product in Magento 2. Below code use to get Product images:

$productImage = $block->getImage($_product, $image);
if ($pos != null) {
    $position = ' style="left:' . $productImage->getWidth() . 'px;'
        . 'top:' . $productImage->getHeight() . 'px;"';

echo $productImage->toHtml();

Currently Getting Image size as per Define in etc/view.xml in Theme, But i want to change Custom Image size for feature product in Homepage.


In your PHTML file you need to set $image = 'homepage_page_grid'; tag as I show here.

then use this $image tag in product Image like below.

$productImage = $block->getImage($_product, $image);

now go to vendor_name/theme/name/etc/view.xml file and add your image with id that you set in PHTML file.

<image id="homepage_page_grid" type="thumbnail">

Hope this will help you.

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.