Magento – How to display the value of an attribute in list.phtml

attributesmagento-1.9PHP

I have this attribute
enter image description here

CODE PHP:

  $attributeCode = 'product_text';

                if ($_product->getData($attributeCode) !== null){
                    echo $_product->getAttributeText($attributeCode);
                }else{
                    echo 'Is NULL';
                }

The problem is I get NULL for each product and I can not display the value of the attribute.

What is wrong?

Thanks in advance![enter image description here]2

Best Answer

if ($_product->getData($attributeCode) !== null){

                    echo $_product->getData($attributeCode);
                }else{

                    echo 'Is NULL';
                }

Syntax:

echo $_product->getData('attribute_code');

echo $_product->getAttributeText('attribute_code'); // in case of dropdown
Related Topic