我想在Controller中获取占位符图片的网址。如何获取网址。
答案 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 );