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="instructions.tab" template="product/tabs/instructions.phtml" group="detailed_info">
                    <arguments>
                        <argument translate="true" name="title" xsi:type="string">Instructions</argument>
                    </arguments>
                </block>

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



Move Block into New Block/Template

Updated February 22, 2016 01:04 AM