1
下面的代碼爲我提供了一個HTML完整的圖像周圍的跨度。在Magento 2中獲取圖像數據
<?php
$productImage = $block->getImage($_product, $image);
echo $productImage->toHtml();
?>
我想知道如何收集圖像的圖像數據在Magento 2,這樣我就可以把togheter的HTML我所想要的。
以下代碼給出了原始圖像的URL。但我想要小尺寸的圖像。
$block->getUrl().'pub/media/catalog/product' . $_product->getImage()
這就是我想要的:
/Magento_Catalog/templates/product/list.php
<?php
$_productCollection = $block->getLoadedProductCollection();
foreach ($_productCollection as $_product){
// Get front image in small size for category view
$get_main_image_url = '';
$get_main_image_width = '';
$get_main_image_height = '';
$get_main_image_alt = '';
echo '<img src="' . $get_main_image_url . '" width="' . $get_main_image_width . '" height="' . $get_main_image_height . '"' . ' alt="' . $get_main_image_alt . '">';
// Get back image in small size for category view
$get_back_image_url = '';
$get_back_image_width = '';
$get_back_image_height = '';
$get_back_image_alt = '';
echo '<img src="' . $get_back_image_url . '" width="' . $get_back_image_width . '" height="' . $get_back_image_height . '"' . ' alt="' . $get_back_image_alt . '">';
}
?>
您面臨的問題是什麼? – urfusion