2016-04-18 23 views
1

Der folgende Code gibt mir HTML voller Spannweiten um das Bild.Erhalte Bilddaten in Magento 2

<?php 

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

echo $productImage->toHtml(); 

?> 

Ich mag würde wissen, wie die Bilddaten für Bilder in Magento 2 so zu sammeln, dass ich togheter HTML setzen kann, wie ich es will.

Der folgende Code gibt mir die URL des ursprünglichen Bildes. Aber ich möchte das kleine Bild.

$block->getUrl().'pub/media/catalog/product' . $_product->getImage() 

Dies ist, was ich will:

/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 . '">'; 

} 

?> 
+0

Was ist das Problem, vor dem Sie stehen? – urfusion

Antwort

0

ich das Bild PHTML Datei gelandet überschrieben, indem eine Datei hier speichern:

[ihre_magenten_installation]/app/design/frontend/[ihr_vendor]/[ihr_theme]/Magento_Catalog/templates/produc t/image_with_borders.phtml

Sie können den Inhalt von image.phtml oder image_with_borders.phtml kopieren. So sieht meine Datei aus:

<?php /** @var $block \Magento\Catalog\Block\Product\Image */ ?> 

<img 
    <?php /* @escapeNotVerified */ echo $block->getCustomAttributes(); ?> 
    src="<?php /* @escapeNotVerified */ echo $block->getImageUrl(); ?>" 
    width="<?php /* @escapeNotVerified */ echo $block->getResizedImageWidth(); ?>" 
    height="<?php /* @escapeNotVerified */ echo $block->getResizedImageHeight(); ?>" 
    alt="<?php /* @escapeNotVerified */ echo $block->stripTags($block->getLabel(), null, true); ?>"/>