Question

Can I customise only product details page without creating any child theme? I just want to modify the product image on the detail page.

Was it helpful?

Solution

app/code/Vendor/Extension/view/frontend/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="product.view.customdetail" template="Vendor_Extension::customdetailpage.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>

app/code/Vendor/Extension/view/frontend/templates/customdetailpage.phtml

<?php $product = $block->getProduct(); ?>
<?php echo $product->getName();?> <!-- add your code as per your need-->

OTHER TIPS

Create the catalog_product_view.xml file in your module, path:app/code/{VendorName}/{PackageName}/view/frontend/layout

And do your customization.

It depends on your needs but anyway, I would recommend you to create a child theme as soon as you want to alter the default template. Create a child theme is quite straightforward, and it allows you to keep your modification in place even when you will upgrade your magento 2 version.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top