How to get placeholder image url Magento2?Images replaced by placeholder image in frontendControl placeholder image width/height in magento 2Sidebar only returns image placeholderMagento 2 placeholder image only showing in thumbnailMagento 2.1.2 placeholder image for product details pagegetImage method always return placeholder image - Magento2.1.7EEMove page.title above image placeholderMagento 2 : how to get image placeholder in admin listing pageMagento 2 product images always returning the placeholder image
Looking after a wayward brother in mother's will
Constructing a CCY Gate
How did the Zip Chip and RocketChip accelerators work for the Apple II?
Is there an evolutionary advantage to having two heads?
Are there mythical creatures in the world of Game of Thrones?
Modern approach to radio buttons
Self-Preservation: How to DM NPCs that Love Living?
Asking bank to reduce APR instead of increasing credit limit
What is the intuition behind uniform continuity?
Is having a hidden directory under /etc safe?
How do I get a list of only the files (not the directories) from a package?
Does a component pouch automatically contain components?
What's the most polite way to tell a manager "shut up and let me work"?
TV show or movie: Diseased people are exiled to a spaceship
Singlequote and backslash
If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?
Is there any Biblical Basis for 400 years of silence between Old and New Testament?
If Sweden was to magically float away, at what altitude would it be visible from the southern hemisphere?
How to detach yourself from a character you're going to kill?
Cryptography and patents
Why would Lupin kill Pettigrew?
What if you don't bring your credit card or debit for incidentals?
What is the most important characteristic of New Weird as a genre?
What people are called "кабан" and why?
How to get placeholder image url Magento2?
Images replaced by placeholder image in frontendControl placeholder image width/height in magento 2Sidebar only returns image placeholderMagento 2 placeholder image only showing in thumbnailMagento 2.1.2 placeholder image for product details pagegetImage method always return placeholder image - Magento2.1.7EEMove page.title above image placeholderMagento 2 : how to get image placeholder in admin listing pageMagento 2 product images always returning the placeholder image
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How to get the placeholder image URL on my template file of product listing page?
magento-2.1 placeholder
add a comment |
How to get the placeholder image URL on my template file of product listing page?
magento-2.1 placeholder
add a comment |
How to get the placeholder image URL on my template file of product listing page?
magento-2.1 placeholder
How to get the placeholder image URL on my template file of product listing page?
magento-2.1 placeholder
magento-2.1 placeholder
edited May 9 '17 at 7:32
Teja Bhagavan Kollepara
2,93242051
2,93242051
asked Jan 19 '17 at 7:59
aton1004aton1004
648823
648823
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
use MagentoStoreModelStoreManager $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(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA );
On Magento 2.2:
Get Helper in Block (phtml)
$imageHelper = $this->helper(MagentoCatalogHelperImage::class);
Get Helper Global
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
Get Placeholder Image Url. User as parameter: 'image', 'smal_image', 'swatch_image' or 'thumbnail'.
$placeholderImageUrl = $imageHelper->getDefaultPlaceholderUrl('image');
Hi saurabh there is a / missing after "placeholder" while getting image source . Also $mediaUrl should be above the img tag, please correct.
– aton1004
Jan 30 '17 at 8:04
yes thanks aton , I known but there are some formating issue that why I did that.
– Saurabh Taletiya
Jan 30 '17 at 12:22
I want to pass the placeholder image path in my API, but when I use getDefaultPlaceholderUrl() it generates image path like: example.com/static/version1551260928/webapi_rest/_view/en_US/…
– Gaurav Agrawal
Feb 27 at 10:36
add a comment |
If you check your store settings you will find option of Product Image place holders
Stores > Configuration > Catalog > Catalog > Product Image Placeholders
You can call the get the value in block and call in your template file.
<?php
protected $_scopeConfig;
public function __construct
(
---
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
---
)
---
$this->_scopeConfig = $scopeConfig;
---
public function getPlaceholderImage()
return $this->_scopeConfig->getValue('catalog/placeholder/image_placeholder'); // Base Image
$this->_scopeConfig->getValue('catalog/placeholder/small_image_placeholder'); // Small Image
$this->_scopeConfig->getValue('catalog/placeholder/swatch_image_placeholder'); // Swatch Image
$this->_scopeConfig->getValue('catalog/placeholder/thumbnail_placeholder'); // Thumbnail Image
In Your Template File Call
$block->getPlaceholderImage();
add a comment |
To get the placeholder image url on the product listing page template, do this:
$imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();
add a comment |
In block, use following method:
public function getPlaceholderImage()
return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));
add a comment |
We should take a look at the class MagentoCatalogHelperImage
For examle:
<?php
namespace VendorModuleHelper;
use MagentoCatalogHelperImageFactory as HelperFactory;
use MagentoFrameworkViewAssetRepository;
class Image
/**
* @var HelperFactory
*/
protected $helperFactory;
/**
* @var Repository
*/
protected $assetRepos;
/**
* Image constructor.
* @param HelperFactory $helperFactory
* @param Repository $repository
*/
public function __construct(
HelperFactory $helperFactory,
Repository $repository
)
$this->assetRepos = $repository;
$this->helperFactory = $helperFactory;
/**
* Get image url
*
* @param $product
* @param $imageId
* @return mixed
*/
public function getImageUrl($product, $imageId = null)
/** @var MagentoCatalogHelperImage $helper */
if ($imageId == null)
$imageId = 'cart_page_product_thumbnail';
$helper = $this->helperFactory->create()
->init($product, $imageId);
return $helper->getUrl();
/**
* Get small place holder image
*
* @return string
*/
public function getPlaceHolderImage()
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->helperFactory->create();
return $this->assetRepos->getUrl($helper->getPlaceholder('small_image'));
add a comment |
If you're trying to get it in any template file. You'll need Magento's image helper. MagentoCatalogHelperImage::class
You can get an instance like this at the top of any .phtml file
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
and get the path to the placeholder image url like this
$imageHelper->getDefaultPlaceholderUrl('small_image')
$imageHelper->getDefaultPlaceholderUrl('image')
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f155437%2fhow-to-get-placeholder-image-url-magento2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
use MagentoStoreModelStoreManager $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(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA );
On Magento 2.2:
Get Helper in Block (phtml)
$imageHelper = $this->helper(MagentoCatalogHelperImage::class);
Get Helper Global
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
Get Placeholder Image Url. User as parameter: 'image', 'smal_image', 'swatch_image' or 'thumbnail'.
$placeholderImageUrl = $imageHelper->getDefaultPlaceholderUrl('image');
Hi saurabh there is a / missing after "placeholder" while getting image source . Also $mediaUrl should be above the img tag, please correct.
– aton1004
Jan 30 '17 at 8:04
yes thanks aton , I known but there are some formating issue that why I did that.
– Saurabh Taletiya
Jan 30 '17 at 12:22
I want to pass the placeholder image path in my API, but when I use getDefaultPlaceholderUrl() it generates image path like: example.com/static/version1551260928/webapi_rest/_view/en_US/…
– Gaurav Agrawal
Feb 27 at 10:36
add a comment |
use MagentoStoreModelStoreManager $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(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA );
On Magento 2.2:
Get Helper in Block (phtml)
$imageHelper = $this->helper(MagentoCatalogHelperImage::class);
Get Helper Global
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
Get Placeholder Image Url. User as parameter: 'image', 'smal_image', 'swatch_image' or 'thumbnail'.
$placeholderImageUrl = $imageHelper->getDefaultPlaceholderUrl('image');
Hi saurabh there is a / missing after "placeholder" while getting image source . Also $mediaUrl should be above the img tag, please correct.
– aton1004
Jan 30 '17 at 8:04
yes thanks aton , I known but there are some formating issue that why I did that.
– Saurabh Taletiya
Jan 30 '17 at 12:22
I want to pass the placeholder image path in my API, but when I use getDefaultPlaceholderUrl() it generates image path like: example.com/static/version1551260928/webapi_rest/_view/en_US/…
– Gaurav Agrawal
Feb 27 at 10:36
add a comment |
use MagentoStoreModelStoreManager $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(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA );
On Magento 2.2:
Get Helper in Block (phtml)
$imageHelper = $this->helper(MagentoCatalogHelperImage::class);
Get Helper Global
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
Get Placeholder Image Url. User as parameter: 'image', 'smal_image', 'swatch_image' or 'thumbnail'.
$placeholderImageUrl = $imageHelper->getDefaultPlaceholderUrl('image');
use MagentoStoreModelStoreManager $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(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA );
On Magento 2.2:
Get Helper in Block (phtml)
$imageHelper = $this->helper(MagentoCatalogHelperImage::class);
Get Helper Global
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
Get Placeholder Image Url. User as parameter: 'image', 'smal_image', 'swatch_image' or 'thumbnail'.
$placeholderImageUrl = $imageHelper->getDefaultPlaceholderUrl('image');
edited Feb 14 '18 at 12:30
Community♦
1
1
answered Jan 19 '17 at 8:49
Saurabh TaletiyaSaurabh Taletiya
564313
564313
Hi saurabh there is a / missing after "placeholder" while getting image source . Also $mediaUrl should be above the img tag, please correct.
– aton1004
Jan 30 '17 at 8:04
yes thanks aton , I known but there are some formating issue that why I did that.
– Saurabh Taletiya
Jan 30 '17 at 12:22
I want to pass the placeholder image path in my API, but when I use getDefaultPlaceholderUrl() it generates image path like: example.com/static/version1551260928/webapi_rest/_view/en_US/…
– Gaurav Agrawal
Feb 27 at 10:36
add a comment |
Hi saurabh there is a / missing after "placeholder" while getting image source . Also $mediaUrl should be above the img tag, please correct.
– aton1004
Jan 30 '17 at 8:04
yes thanks aton , I known but there are some formating issue that why I did that.
– Saurabh Taletiya
Jan 30 '17 at 12:22
I want to pass the placeholder image path in my API, but when I use getDefaultPlaceholderUrl() it generates image path like: example.com/static/version1551260928/webapi_rest/_view/en_US/…
– Gaurav Agrawal
Feb 27 at 10:36
Hi saurabh there is a / missing after "placeholder" while getting image source . Also $mediaUrl should be above the img tag, please correct.
– aton1004
Jan 30 '17 at 8:04
Hi saurabh there is a / missing after "placeholder" while getting image source . Also $mediaUrl should be above the img tag, please correct.
– aton1004
Jan 30 '17 at 8:04
yes thanks aton , I known but there are some formating issue that why I did that.
– Saurabh Taletiya
Jan 30 '17 at 12:22
yes thanks aton , I known but there are some formating issue that why I did that.
– Saurabh Taletiya
Jan 30 '17 at 12:22
I want to pass the placeholder image path in my API, but when I use getDefaultPlaceholderUrl() it generates image path like: example.com/static/version1551260928/webapi_rest/_view/en_US/…
– Gaurav Agrawal
Feb 27 at 10:36
I want to pass the placeholder image path in my API, but when I use getDefaultPlaceholderUrl() it generates image path like: example.com/static/version1551260928/webapi_rest/_view/en_US/…
– Gaurav Agrawal
Feb 27 at 10:36
add a comment |
If you check your store settings you will find option of Product Image place holders
Stores > Configuration > Catalog > Catalog > Product Image Placeholders
You can call the get the value in block and call in your template file.
<?php
protected $_scopeConfig;
public function __construct
(
---
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
---
)
---
$this->_scopeConfig = $scopeConfig;
---
public function getPlaceholderImage()
return $this->_scopeConfig->getValue('catalog/placeholder/image_placeholder'); // Base Image
$this->_scopeConfig->getValue('catalog/placeholder/small_image_placeholder'); // Small Image
$this->_scopeConfig->getValue('catalog/placeholder/swatch_image_placeholder'); // Swatch Image
$this->_scopeConfig->getValue('catalog/placeholder/thumbnail_placeholder'); // Thumbnail Image
In Your Template File Call
$block->getPlaceholderImage();
add a comment |
If you check your store settings you will find option of Product Image place holders
Stores > Configuration > Catalog > Catalog > Product Image Placeholders
You can call the get the value in block and call in your template file.
<?php
protected $_scopeConfig;
public function __construct
(
---
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
---
)
---
$this->_scopeConfig = $scopeConfig;
---
public function getPlaceholderImage()
return $this->_scopeConfig->getValue('catalog/placeholder/image_placeholder'); // Base Image
$this->_scopeConfig->getValue('catalog/placeholder/small_image_placeholder'); // Small Image
$this->_scopeConfig->getValue('catalog/placeholder/swatch_image_placeholder'); // Swatch Image
$this->_scopeConfig->getValue('catalog/placeholder/thumbnail_placeholder'); // Thumbnail Image
In Your Template File Call
$block->getPlaceholderImage();
add a comment |
If you check your store settings you will find option of Product Image place holders
Stores > Configuration > Catalog > Catalog > Product Image Placeholders
You can call the get the value in block and call in your template file.
<?php
protected $_scopeConfig;
public function __construct
(
---
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
---
)
---
$this->_scopeConfig = $scopeConfig;
---
public function getPlaceholderImage()
return $this->_scopeConfig->getValue('catalog/placeholder/image_placeholder'); // Base Image
$this->_scopeConfig->getValue('catalog/placeholder/small_image_placeholder'); // Small Image
$this->_scopeConfig->getValue('catalog/placeholder/swatch_image_placeholder'); // Swatch Image
$this->_scopeConfig->getValue('catalog/placeholder/thumbnail_placeholder'); // Thumbnail Image
In Your Template File Call
$block->getPlaceholderImage();
If you check your store settings you will find option of Product Image place holders
Stores > Configuration > Catalog > Catalog > Product Image Placeholders
You can call the get the value in block and call in your template file.
<?php
protected $_scopeConfig;
public function __construct
(
---
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
---
)
---
$this->_scopeConfig = $scopeConfig;
---
public function getPlaceholderImage()
return $this->_scopeConfig->getValue('catalog/placeholder/image_placeholder'); // Base Image
$this->_scopeConfig->getValue('catalog/placeholder/small_image_placeholder'); // Small Image
$this->_scopeConfig->getValue('catalog/placeholder/swatch_image_placeholder'); // Swatch Image
$this->_scopeConfig->getValue('catalog/placeholder/thumbnail_placeholder'); // Thumbnail Image
In Your Template File Call
$block->getPlaceholderImage();
edited May 24 at 8:41
Maarten Wolfsen
656731
656731
answered Jan 19 '17 at 8:51
PriyankPriyank
5,62742253
5,62742253
add a comment |
add a comment |
To get the placeholder image url on the product listing page template, do this:
$imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();
add a comment |
To get the placeholder image url on the product listing page template, do this:
$imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();
add a comment |
To get the placeholder image url on the product listing page template, do this:
$imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();
To get the placeholder image url on the product listing page template, do this:
$imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();
edited Dec 13 '17 at 6:57
Priyank
5,62742253
5,62742253
answered Jan 19 '17 at 8:43
Aaron AllenAaron Allen
6,90421131
6,90421131
add a comment |
add a comment |
In block, use following method:
public function getPlaceholderImage()
return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));
add a comment |
In block, use following method:
public function getPlaceholderImage()
return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));
add a comment |
In block, use following method:
public function getPlaceholderImage()
return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));
In block, use following method:
public function getPlaceholderImage()
return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));
answered Sep 13 '17 at 14:41
vladPavlovvladPavlov
3592514
3592514
add a comment |
add a comment |
We should take a look at the class MagentoCatalogHelperImage
For examle:
<?php
namespace VendorModuleHelper;
use MagentoCatalogHelperImageFactory as HelperFactory;
use MagentoFrameworkViewAssetRepository;
class Image
/**
* @var HelperFactory
*/
protected $helperFactory;
/**
* @var Repository
*/
protected $assetRepos;
/**
* Image constructor.
* @param HelperFactory $helperFactory
* @param Repository $repository
*/
public function __construct(
HelperFactory $helperFactory,
Repository $repository
)
$this->assetRepos = $repository;
$this->helperFactory = $helperFactory;
/**
* Get image url
*
* @param $product
* @param $imageId
* @return mixed
*/
public function getImageUrl($product, $imageId = null)
/** @var MagentoCatalogHelperImage $helper */
if ($imageId == null)
$imageId = 'cart_page_product_thumbnail';
$helper = $this->helperFactory->create()
->init($product, $imageId);
return $helper->getUrl();
/**
* Get small place holder image
*
* @return string
*/
public function getPlaceHolderImage()
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->helperFactory->create();
return $this->assetRepos->getUrl($helper->getPlaceholder('small_image'));
add a comment |
We should take a look at the class MagentoCatalogHelperImage
For examle:
<?php
namespace VendorModuleHelper;
use MagentoCatalogHelperImageFactory as HelperFactory;
use MagentoFrameworkViewAssetRepository;
class Image
/**
* @var HelperFactory
*/
protected $helperFactory;
/**
* @var Repository
*/
protected $assetRepos;
/**
* Image constructor.
* @param HelperFactory $helperFactory
* @param Repository $repository
*/
public function __construct(
HelperFactory $helperFactory,
Repository $repository
)
$this->assetRepos = $repository;
$this->helperFactory = $helperFactory;
/**
* Get image url
*
* @param $product
* @param $imageId
* @return mixed
*/
public function getImageUrl($product, $imageId = null)
/** @var MagentoCatalogHelperImage $helper */
if ($imageId == null)
$imageId = 'cart_page_product_thumbnail';
$helper = $this->helperFactory->create()
->init($product, $imageId);
return $helper->getUrl();
/**
* Get small place holder image
*
* @return string
*/
public function getPlaceHolderImage()
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->helperFactory->create();
return $this->assetRepos->getUrl($helper->getPlaceholder('small_image'));
add a comment |
We should take a look at the class MagentoCatalogHelperImage
For examle:
<?php
namespace VendorModuleHelper;
use MagentoCatalogHelperImageFactory as HelperFactory;
use MagentoFrameworkViewAssetRepository;
class Image
/**
* @var HelperFactory
*/
protected $helperFactory;
/**
* @var Repository
*/
protected $assetRepos;
/**
* Image constructor.
* @param HelperFactory $helperFactory
* @param Repository $repository
*/
public function __construct(
HelperFactory $helperFactory,
Repository $repository
)
$this->assetRepos = $repository;
$this->helperFactory = $helperFactory;
/**
* Get image url
*
* @param $product
* @param $imageId
* @return mixed
*/
public function getImageUrl($product, $imageId = null)
/** @var MagentoCatalogHelperImage $helper */
if ($imageId == null)
$imageId = 'cart_page_product_thumbnail';
$helper = $this->helperFactory->create()
->init($product, $imageId);
return $helper->getUrl();
/**
* Get small place holder image
*
* @return string
*/
public function getPlaceHolderImage()
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->helperFactory->create();
return $this->assetRepos->getUrl($helper->getPlaceholder('small_image'));
We should take a look at the class MagentoCatalogHelperImage
For examle:
<?php
namespace VendorModuleHelper;
use MagentoCatalogHelperImageFactory as HelperFactory;
use MagentoFrameworkViewAssetRepository;
class Image
/**
* @var HelperFactory
*/
protected $helperFactory;
/**
* @var Repository
*/
protected $assetRepos;
/**
* Image constructor.
* @param HelperFactory $helperFactory
* @param Repository $repository
*/
public function __construct(
HelperFactory $helperFactory,
Repository $repository
)
$this->assetRepos = $repository;
$this->helperFactory = $helperFactory;
/**
* Get image url
*
* @param $product
* @param $imageId
* @return mixed
*/
public function getImageUrl($product, $imageId = null)
/** @var MagentoCatalogHelperImage $helper */
if ($imageId == null)
$imageId = 'cart_page_product_thumbnail';
$helper = $this->helperFactory->create()
->init($product, $imageId);
return $helper->getUrl();
/**
* Get small place holder image
*
* @return string
*/
public function getPlaceHolderImage()
/** @var MagentoCatalogHelperImage $helper */
$helper = $this->helperFactory->create();
return $this->assetRepos->getUrl($helper->getPlaceholder('small_image'));
edited Oct 12 '17 at 9:14
answered Oct 12 '17 at 9:06
Khoa TruongDinhKhoa TruongDinh
22.4k64390
22.4k64390
add a comment |
add a comment |
If you're trying to get it in any template file. You'll need Magento's image helper. MagentoCatalogHelperImage::class
You can get an instance like this at the top of any .phtml file
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
and get the path to the placeholder image url like this
$imageHelper->getDefaultPlaceholderUrl('small_image')
$imageHelper->getDefaultPlaceholderUrl('image')
add a comment |
If you're trying to get it in any template file. You'll need Magento's image helper. MagentoCatalogHelperImage::class
You can get an instance like this at the top of any .phtml file
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
and get the path to the placeholder image url like this
$imageHelper->getDefaultPlaceholderUrl('small_image')
$imageHelper->getDefaultPlaceholderUrl('image')
add a comment |
If you're trying to get it in any template file. You'll need Magento's image helper. MagentoCatalogHelperImage::class
You can get an instance like this at the top of any .phtml file
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
and get the path to the placeholder image url like this
$imageHelper->getDefaultPlaceholderUrl('small_image')
$imageHelper->getDefaultPlaceholderUrl('image')
If you're trying to get it in any template file. You'll need Magento's image helper. MagentoCatalogHelperImage::class
You can get an instance like this at the top of any .phtml file
$imageHelper = MagentoFrameworkAppObjectManager::getInstance()->get(MagentoCatalogHelperImage::class);
and get the path to the placeholder image url like this
$imageHelper->getDefaultPlaceholderUrl('small_image')
$imageHelper->getDefaultPlaceholderUrl('image')
answered Apr 17 '18 at 16:28
LeonLeon
107
107
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f155437%2fhow-to-get-placeholder-image-url-magento2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown