9

I'm in Magento2 and the getDescription(); does not work.

I'm in the file Magento_Catalog/templates/product/list.phtml if that's relevant.

1
  • I want show description in additional div after tabs section on product page, how can i achieve this. Please help, Thanks in advance. Aug 14, 2019 at 11:24

4 Answers 4

18

In Store > Attributes > Product > Description > Storefront Properties set Visible on Catalog Pages on Storefront and Used in Product Listing to TRUE.

In your code list.phtml you can use:

<?php echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($_product, $_product->getDescription(), 'description') ?>

or

<?php echo $_product->getDescription() ?>
1

It should work fine..

<?php echo $_product->getDescription(); ?>
1
  • please check out the accepted answer. you answer is redundant and is missing important parts Aug 14, 2019 at 7:39
1

Try this:

$productCollection = $this->helper('\Magento\Catalog\Model\ProductFactory');

$product = $productCollection->create()->load($id);

$description = $product->getDescription();
2
  • Hi and welcome to stackoverflow! you're answer does exactly what mine does. Nov 12, 2018 at 9:28
  • You helped me with $description = $product->getDescription(); Oct 17, 2019 at 12:09
0

See /vendor/magento/module-catalog/view/frontend/templates/product/view/description.phtml

/**
 * Product description template
 *
 * @var $block \Magento\Catalog\Block\Product\View\Description
 */
?>
<?php /* @escapeNotVerified */ echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($block->getProduct(), $block->getProduct()->getDescription(), 'description') ?>
4
  • I already tried that. It's not working. If you have a look at the class of the object that returned by getProduct you will see, that there's no getDescription() Apr 6, 2016 at 8:22
  • getDescription should be a magic method, where the string after "get" is the attribute name
    – ahnbizcad
    Sep 12, 2016 at 4:26
  • Doesn't care if its not in the object, thus not a magic getter. :)
    – Max
    Oct 26, 2017 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.