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.

  • Yes , you can override a view files and achieve what you are looking for . create custom module/theme for this and override the core files . Please go through this it might help you - classyllama.com/blog/template-override-m2
    – Mac
    Commented Sep 14, 2018 at 15:06
  • You can remove the blocks from xml for your theme. Commented Sep 14, 2018 at 15:08
  • Please can you update me what code i need to add in catalog_product_view.xml file? Commented Sep 14, 2018 at 15:11
  • Hello @jafarpinjar, did you got your solution ?
    – Pawan
    Commented Sep 14, 2018 at 16:35
  • no, i am trying the answer which is posted here, and confirm you once it worked. Commented Sep 15, 2018 at 6:33

2 Answers 2


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


<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="content">
        <block class="Magento\Catalog\Block\Product\View" name="custom.product.view" template="Magento_Catalog::product/customview.phtml" before="-"/>
    <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" />

Create a customview.phtml at:


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

Result will be: enter image description here

  • Nice, i used your code, its working great, but small change i need , i have created custom attribute for product called "is_custom", if that value is yes then i need to load this file else i need to use default one. is that can be checked and use? Commented Sep 17, 2018 at 6:25
  • Hello @jafarpinjar, Good to know that it worked. If you want to load this layout based on condition you can follow emiprotechnologies.com/news/magento-technical-notes-60/post/…
    – Pawan
    Commented Sep 17, 2018 at 16:50
  • if still you found any issue, Please let me know.
    – Pawan
    Commented Sep 17, 2018 at 16:50
  • hello @pavan, i couldn't get from the above link, What i need exactly is i need to use that layout file code based on the product attribute value, i have created product attribute called 'is_custom' if it is set as Yes then i need to load the above phtml else i need to use default magento product detail page, is that can be done? Commented Sep 18, 2018 at 6:35

This is to just give an idea, please change the code accordingly as the code is neither complete or verified.

Setup a new magento 2 extension.

Create catalog_product_view.xml on the following path


with something like

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="content">
        <block class="{YourVendor}\{YourModule}\Block\Product\View" name="{vendor}.{module}.product.view" template="product/view.phtml" before="-"/>
        <referenceContainer name="product.info.main" remove="true"></referenceContainer>

Now Create a Block file View.php on path


Extend magento's base block class for product view, something like

namespace {YourVendor}\{YourModule}\Block\Product;
class View extends \Magento\Catalog\Block\Product\View {

Also create the template file view.phtml on path


You can use the functions you defined in the View Block class

  • hi. @Hammad, I tried your code, from that i can only remove name and price details, but still i can see image and review section, i need to remove entirely all the default blocks of product detail page , ans i need to add my own code there, is that possible? Commented Sep 15, 2018 at 10:06
  • @jafarpinjar, if you open the main catalog_product_view.xml file, you can see a lot of block created there, you will have to remove them as well. it is a good approach if you use the newly created xml file to remove them, rather than removing them from the main file Commented Sep 17, 2018 at 11:48
  • hi, @Hammad, yes i used your code only but, as i asked is it possible to do like that? Commented Sep 17, 2018 at 14:33
  • @jafarpinjar, that is what i mean with my above comment.. it is possible, you just have to remove the default blocks loaded on the product pages Commented Sep 17, 2018 at 15:44
  • Please refer the link below for adding custom layouts magento.stackexchange.com/questions/251880/…
    – Liz Eipe C
    Commented Sep 8, 2020 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.