After about a week reading through the Magento 2 Docs - layout instructions, and some other stack exchange Q's and A's, I still having a hard time to figure out how to insert a custom block in to the specific location of the product page.
What I have so far,
in to the top of this page: /app/design/frontend/<Vendor>/<theme>/Magento_Catalog/templates/product/view/details.phtml
I have inserted this line of code:
echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();
In the product "Custom Lyout Update", i have inserted this XML
<referenceContainer name="block_identifier" >
<block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml" />
</referenceContainer>
The only time I can see contents of my test.php file is when I change referenceContainer name to predefined blocks as "content" or "product.info".
Links that I found useful:
Magento2- Display Static Block in Phtml file & CMS page
Magento 2 - How to call a custom phtml file in another phtml file, xml layout, static block and cms page?
How to show the static blocks in Magento 2?
Magento 2 tutorial – How to use the new front-end templating system
My current temp fix
I insert test.phtml file to a specific product this way.
<referenceContainer name="main" >
<container name="product.info.desc" htmlTag="div" htmlId="product-info-desc-id" htmlClass="product-info-class" >
<block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml" />
</container>
</referenceContainer>
<move element="product.info.desc" destination="content" after="product.info.media" />
Any help is greatly appreciated. Thank you.
frontend
or?product_id_whatever.phtml
, and I need to insert it as block and position it before description/review tabs.