Magento 2-保持产品图像长宽比
我正在使用Magento 2类别页面。 但是我不知道如何保持产品图像的宽高比。 在magento 1.x中,我可以获取图像src以使用以下代码。 <?php echo $this->helper('catalog/image') ->init($_product, 'small_image') ->constrainOnly(FALSE) ->keepAspectRatio(TRUE) ->keepFrame(FALSE) ->resize(300); ?> 但是在magento 2中,我可以在/app/design/frontend/Magento/luma/etc/view.xml文件中设置图像大小。 <image id="category_page_grid" type="small_image"> <width>240</width> <height>300</height> </image> <image id="category_page_list" type="small_image"> <width>240</width> <height>300</height> </image> 我试图用“自动”输入高度,但是没有用。 我也尝试只输入宽度,但是它也没有用。 而且我在Magento_Catalog / templates / product / list.phtml文件中找到了以下用于显示产品图片的代码。 <?php $productImage = $block->getImage($_product, $image); ?> <a href="<?php echo $_product->getProductUrl() ?>" class="product …