3

I add a Custom TEXT Attribute (more_info) to my Magento 2 Store and I will show the Value to my product.info.main Page.

I add

mytheme\Magento_Catalog\layout\catalog_product_view.xml

<referenceBlock name="product.info.main">
    <block class="Magento\Catalog\Block\Product\View" template="product/view/more_info.phtml" >
    </block>
</referenceBlock>

and

mytheme\Magento_Catalog\templates\product\view\more_info.phtml

<?php $_product = $this->getProduct(); ?>
    <?php echo $_product->getAttributeText('more_info') ?>

but they show me no value:-(

I'm very thankful for any help.

1
  • try with <block class="Magento\Catalog\Block\Product\View" template="Magento_Catalog::product/view/more_info.phtml" > Dec 22, 2016 at 12:58

2 Answers 2

3

You need to do this changes,

Change your xml like this,

<referenceBlock name="product.info.main">
    <block class="Magento\Catalog\Block\Product\View" template="Magento_Catalog::product/view/more_info.phtml"></block>
</referenceBlock>

And modify your phtml file :

mytheme\Magento_Catalog\templates\product\view\more_info.phtml


<?php $_product = $block->getProduct(); ?>
<?php echo $_product->getAttributeText('more_info') ?>

OR

<?php $_product = $block->getProduct(); ?>
<?php echo $_product->getResource()->getAttribute('more_info')->getFrontend()->getValue($_product) ?>
3
  • the .xml is correct, they show me some test text from the phtml file but the attribute value is not showing with your phtml code. Dec 22, 2016 at 15:26
  • verify that you have set attribute value for that product in admin. Dec 23, 2016 at 3:18
  • I update my answer, you can also try another way I mension. Dec 23, 2016 at 3:21
1

Try to use like this

<referenceBlock name="product.info.main">
    <block class="Magento\Catalog\Block\Product\View" template="Magento_Catalog::product/view/more_info.phtml"></block>
</referenceBlock>
2

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.