0

I can't able to add/include my custom phtml file on product detailed page.

Here is my entire flow :

  1. Added the following code in app/design/frontend/Themename/themedirectory/Magento_Catalog/layout/catalog_product_view.xml file

    <body>
     <referenceContainer name="content">
     <container name="product-main-content" htmlTag="div" htmlClass="product-main-content" before="-">
     </container>
     </referenceContainer>
     <referenceContainer name="content.top.most">
     <container name="custom.block.sec" htmlTag="div" htmlClass="custom-class" before="-">
     <block class="Magento\Catalog\Block\Product\View" name="my_custom" template="Vendorname_Modulename::custom.phtml" />
     </container>
     </referenceContainer>
     <block class="Magento\Theme\Block\Html\Title" name="page.main.sub.title" template="Magento_Theme::html/title.phtml"/>
     <referenceBlock name="product.info.details">
     <block class="Magento\Catalog\Block\Product\View" name="cmsinfo.tab" as="cmsinfo" template="product/view/cms_tab.phtml" group="detailed_info" >
     <arguments>
     <argument translate="true" name="title" xsi:type="string">Custom Tab</argument>
     </arguments>
     </block>
     </referenceBlock>
     <move element="custom.block.sec" destination="product.info.main" before="-"/>
    </body>
    
  2. Added the custom.phtml file in app/code/Vendorname/Modulename/view/frontend/templates/custom.phtml

  3. custom.phtml file content

    Custom File Works

I referred this link as well but no luck.

But its not working. Why?

Can anyone let me know what's the issue & how to add the custom file in product page?

Aasim Goriya
5,4622 gold badges30 silver badges54 bronze badges
asked Jan 23, 2019 at 9:09
1
  • I've edited for you :) Commented Jan 23, 2019 at 9:20

1 Answer 1

1

Please try this way in your app/design/frontend/Themename/themedirectory/Magento_Catalog/layout/catalog_product_view.xml file

<referenceContainer name="content.top.most">
 <container name="custom.block.sec" htmlTag="div" htmlClass="custom-class" before="-">
 <block class="Magento\Catalog\Block\Product\View" name="my_custom" template="Vendorname_Modulename::custom.phtml" />
 </container>
</referenceContainer>
<move element="custom.block.sec" destination="product.info.main" before="-"/>

After that please check with clear your cache.

answered Jan 23, 2019 at 9:26
15
  • Thanks for your answer, I just tried the code but its not working. I have updated my entire code in question. Please check it Commented Jan 23, 2019 at 9:41
  • did you clear cache after this changes ? Commented Jan 23, 2019 at 9:43
  • Yes cleared cache by php bin/magento cache:flush and php bin/magento cache:clean But its not working Commented Jan 23, 2019 at 9:47
  • its strange, because its working fine for me. can you please check your custom module name is Vendorname_Modulename which is correct ? Commented Jan 23, 2019 at 9:49
  • 1
    @Mesk clear your cache and refresh cache from admin and once check. Commented Jan 23, 2019 at 10:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.