如何在Magento 2中获取占位符图像的URL?

时间:2017-12-13 06:08:15

标签: magento magento2

我想在Controller中获取占位符图片的网址。如何获取网址。

1 个答案:

答案 0 :(得分:0)

如果您想在模板文件中获取占位符图片网址,可以使用

\Magento\Store\Model\StoreManager $storeManager

$this->storeManager = $storeManager;
$path =
catalog/placeholder/thumbnail_placeholder OR
catalog/placeholder/swatch_image_placeholder OR
catalog/placeholder/small_image_placeholder OR
catalog/placeholder/image_placeholder OR

public function getConfig($config_path)
{
    return $this->storeManager->getStore()->getConfig($config_path);
}

<img src = $mediaUrl.'catalog/product/placeholder'.$this->getConfig($path) />
    $mediaUrl = $this ->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA );