1

I am looking for code how we can load custom template file for product detail page?

I need to remove default magento2 detail page,

I have tried below code to achieve it,

 {{block class="Magento\Framework\View\Element\Template" name="product_file" template="Magento_Catalog::product.phtml"}}

I created new cms page, and from category list page, I am redirecting to this page for each of the products by passing parameter with productId.

In detail page i used below code to get product data.

$proId = $_REQUEST['id'];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($proId);
$proSku  = $product->getSku();
$product_title = $product->getName();

Is this can be achieved any other simple way?

1 Answer 1

0

This is completly wrong way to achieve the above mentioned functionality.

You don't need to change any product links on category page. Directly in your theme you need to create below file:

app/design/frontend/<<PACKAGE>>/<<THEME>>/Magento_Catalog/layout/catalog_product_view.xml

In catalog_product_view.xml file, you can use 'remove' attribute to delete unwanted blocks.

Using below Block class, you can add custom template in layout file.

Magento\Catalog\Block\Product\View

Advantage of this approach is, you are not making any changes on Code level and utilizing all product functionality.

Just to achieve your functionality, you are making changes in layout.

7
  • Hi pankaj, thanks for your answer, i need to remove all default blocks like images,reviews, title and price etc, completely i am going to add my custom code in that template file. Commented Sep 3, 2018 at 7:18
  • yes if your remove the container, it will delete all child blocks. and then you can add your own custom container and block Commented Sep 3, 2018 at 7:22
  • can you please update me catalog_product_view.xml file? Commented Sep 3, 2018 at 7:23
  • you just need to use remove attribute with true. you can use referenceContainer tag with name and remove attribute Commented Sep 3, 2018 at 7:25
  • I need that code please, could you update me? Commented Sep 3, 2018 at 7:36

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.