Magento 2 – Add Custom PHTML File to Product Page cataloglayoutmagento2 How to add custom .phtml file in product details page. I also try this code in catalog_product_view.xml file, but can't working. Best Answer Please use below code: <?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <block after="product.info.details" class="Vendor/Module/Block/Module" name="extra" template="Vendor_Module::extra.phtml" /> </referenceContainer> </body> </page> Related SolutionsMagento Layout PHTML – How to Add Custom PHTML in Product View Page That only change in xml file Replace this <reference name="product.info"> with <reference name="content"> Add this content in reference tag <action method="addToParentGroup"><group>detailed_info</group></action> <action method="setTitle" translate="value"><value>Information</value></action> Magento2 Catalog Frontend – How to Add Custom phtml in Catalog View Page Create catalog_category_view.xml app/code/Vendor/Module/view/frontend/layout/catalog_category_view.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Vendor_Module::myCustomFile.phtml" /> </referenceContainer> </body> </page> Now create myCustomFile.phtml and place your code app/code/Vendor/Module/view/frontend/templates/myCustomFile.phtml <?php echo "This is my custom file for product list page"; ?> Related TopicMagento 2 – Get Product Detail at Custom PHTML in Catalog View LayoutMagento – How to add a custom TAB to magento2 product detailMagento 2.2.4 – Not Able to Add Custom phtml File on Product Page
Best Answer
Please use below code: