How to fetch product data into custom .phtml block on product view

by Ryan Holton   Last Updated January 11, 2019 12:09 PM

I'm having trouble trying to fetch Product data such as price, SKU etc into a custom .phtml file referenced as a block within my catalog_product_view.xml file.

Here's what I'm struggling with... I'm able to fetch product data using:

$product = $block->getProduct();

within a custom product tab under: Magento_Catalog/templates/product/tabs/instructions.phtml referenced as:

<block class="Magento\Catalog\Block\Product\View" name="" template="product/tabs/instructions.phtml" group="detailed_info">
                        <argument translate="true" name="title" xsi:type="string">Instructions</argument>

within my catalog_product_view.xml file.

However, when I try to pull through product information in a template block: Magento_Catalog/templates/html/myblock.phtml it doesn't work.

The block is referenced as:

<block class="Magento\Framework\View\Element\Template" group="detailed_info" name="callout" template="Magento_Catalog::html/left-callout.phtml" />

Many thanks

Related Questions

Display related products block in product view

Updated May 26, 2017 13:09 PM

How to keep .phtml files lean and clean?

Updated August 22, 2015 18:04 PM