Skip to content

How to display product image with custom role on carousel?

I am trying to include a product image that has a specific custom role (in the example below its hover_img)

The file I am doing this on is:

vendor/magento/module-page-builder/view/frontend/templates/catalog/product/widget/content/carousel.phtml

I am trying to display it by doing this:

<?php
$customImg = $_item->getResource()->getAttribute('hover_img')->getFrontend()->getValue($_item);
?>

<?= $customImg ?>

But nothing is coming back its just empty, wondering if anyone knows the correct way on how to do this please?

(The end result of this is so that when hovering over a product image in the carousel the hover image of that product is shown but I am struggling to pull in the image with a custom role)