Magento 2 – Load Custom Product Detail Page Instead of Default

magento2productproduct-view

I am trying to remove default product detail page content, can i load custom phtml file for product detail page along with the image?

I need to remove all the default blocks of product detail page and show only my template content.

Is that can be done? Because i need to custom code in that template file to interact with external api with the product id.

How this can be achieved? Please anyone suggest me.

Best Answer

There is no need of module, You just need to create a catalog_product_view.xml at:

app/design/frontend/[Package]/[theme]/Magento_Catalog/layout/catalog_product_view.xml

<page layout="1column" 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 class="Magento\Catalog\Block\Product\View" name="custom.product.view" template="Magento_Catalog::product/customview.phtml" before="-"/>
    </referenceContainer>
    <referenceContainer name="product.info.main" remove="true"></referenceContainer>
    <referenceContainer name="product.info.media" remove="true"></referenceContainer>
    <referenceContainer name="product.info.details" remove="true"></referenceContainer>
    <referenceBlock name="page.main.title" remove="true" />
</body>
</page>

Create a customview.phtml at:

app/design/frontend/[Package]/[theme]/Magento_Catalog/templates/product/customview.phtml

<?php $product = $block->getProduct(); ?>
<?php echo $product->getName();?> <!-- whatever you want -->

Result will be: enter image description here

Related Topic