0

This probably easy and I'm forgetting something but...

product.price.final is a default xml block of magento why does it always returns false when I call it on my custom phtml.

<div>
  <?= $block->getLayout()->getBlock('product.price.final')->toHtml() ?>
</div>

Obs: this is not on catalog_product_view page

2 Answers 2

0

If you are trying to call a Magento 2 block in a custom .phtml file and it is returning false, it could be due to a few different issues:

  1. The block class might not be defined correctly in the layout XML file. Make sure the class path and name are correct.
  2. The block might not be instantiated in the layout XML file. Make sure the block is defined and instantiated in the layout XML file with the correct name.
  3. The block might not have the correct template set. Make sure the template file path is correct and that the file exists.
  4. The block might not be in the correct block group. Make sure the block is in the correct block group and that the group is being called in the .phtml file.

It is also possible that the issue is not with the block, but with the .phtml file. Make sure that the .phtml file is being called correctly in the layout XML file and that it exists in the correct location.

I suggest you to check and match the following :

  • block class defined in layout xml
  • block instantiation in layout xml
  • block template
  • block group name
  • .phtml file call in layout xml

Please let me know, if you have any specific error message or any other details, I would be happy to help you with that.

THANKS.

1
  • Hm, Im calling the magento block directly on phtml, phtml file is not the problem since other things is being displayed. The magento block xml is correct also since was made by magento haha'
    – IndexError
    Jan 17 at 11:34
0

Try this: Go to app/design/frontend/Vendor/theme/Magento_Catalog/layout/catalog_product_view.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
         <move element="product.info.price" destination="product.info.addtocart.additional" before="-"/>
    </body>
</page>```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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