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;








8















How to get the placeholder image URL on my template file of product listing page?










share|improve this question






























    8















    How to get the placeholder image URL on my template file of product listing page?










    share|improve this question


























      8












      8








      8


      3






      How to get the placeholder image URL on my template file of product listing page?










      share|improve this question
















      How to get the placeholder image URL on my template file of product listing page?







      magento-2.1 placeholder






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 9 '17 at 7:32









      Teja Bhagavan Kollepara

      2,93242051




      2,93242051










      asked Jan 19 '17 at 7:59









      aton1004aton1004

      648823




      648823




















          6 Answers
          6






          active

          oldest

          votes


















          8














           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');






          share|improve this answer

























          • 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


















          6














          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();





          share|improve this answer
































            3














            To get the placeholder image url on the product listing page template, do this:



            $imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();





            share|improve this answer
































              2














              In block, use following method:



              public function getPlaceholderImage() 
              return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));






              share|improve this answer






























                1














                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'));







                share|improve this answer
































                  0














                  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')





                  share|improve this answer























                    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
                    );



                    );













                    draft saved

                    draft discarded


















                    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









                    8














                     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');






                    share|improve this answer

























                    • 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















                    8














                     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');






                    share|improve this answer

























                    • 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













                    8












                    8








                    8







                     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');






                    share|improve this answer















                     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');







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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

















                    • 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













                    6














                    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();





                    share|improve this answer





























                      6














                      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();





                      share|improve this answer



























                        6












                        6








                        6







                        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();





                        share|improve this answer















                        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();






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited May 24 at 8:41









                        Maarten Wolfsen

                        656731




                        656731










                        answered Jan 19 '17 at 8:51









                        PriyankPriyank

                        5,62742253




                        5,62742253





















                            3














                            To get the placeholder image url on the product listing page template, do this:



                            $imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();





                            share|improve this answer





























                              3














                              To get the placeholder image url on the product listing page template, do this:



                              $imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();





                              share|improve this answer



























                                3












                                3








                                3







                                To get the placeholder image url on the product listing page template, do this:



                                $imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();





                                share|improve this answer















                                To get the placeholder image url on the product listing page template, do this:



                                $imageUrl = $block->getImage($block->getProduct(), 'category_page_grid')->getImageUrl();






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                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





















                                    2














                                    In block, use following method:



                                    public function getPlaceholderImage() 
                                    return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));






                                    share|improve this answer



























                                      2














                                      In block, use following method:



                                      public function getPlaceholderImage() 
                                      return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));






                                      share|improve this answer

























                                        2












                                        2








                                        2







                                        In block, use following method:



                                        public function getPlaceholderImage() 
                                        return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));






                                        share|improve this answer













                                        In block, use following method:



                                        public function getPlaceholderImage() 
                                        return sprintf('<img src="%s"/>', $this->getViewFileUrl('Magento_Catalog::images/product/placeholder/thumbnail.jpg'));







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Sep 13 '17 at 14:41









                                        vladPavlovvladPavlov

                                        3592514




                                        3592514





















                                            1














                                            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'));







                                            share|improve this answer





























                                              1














                                              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'));







                                              share|improve this answer



























                                                1












                                                1








                                                1







                                                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'));







                                                share|improve this answer















                                                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'));








                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Oct 12 '17 at 9:14

























                                                answered Oct 12 '17 at 9:06









                                                Khoa TruongDinhKhoa TruongDinh

                                                22.4k64390




                                                22.4k64390





















                                                    0














                                                    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')





                                                    share|improve this answer



























                                                      0














                                                      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')





                                                      share|improve this answer

























                                                        0












                                                        0








                                                        0







                                                        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')





                                                        share|improve this answer













                                                        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')






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Apr 17 '18 at 16:28









                                                        LeonLeon

                                                        107




                                                        107



























                                                            draft saved

                                                            draft discarded
















































                                                            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.




                                                            draft saved


                                                            draft discarded














                                                            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





















































                                                            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







                                                            Popular posts from this blog

                                                            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                                                            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                                                            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form