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?

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.

  • Thanks for your answer, I just tried the code but its not working. I have updated my entire code in question. Please check it – Mesk Jan 23 at 9:41
  • did you clear cache after this changes ? – Aasim Goriya Jan 23 at 9:43
  • Yes cleared cache by php bin/magento cache:flush and php bin/magento cache:clean But its not working – Mesk Jan 23 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 ? – Aasim Goriya Jan 23 at 9:49
  • 1
    @Mesk clear your cache and refresh cache from admin and once check. – Rizwan Khan Jan 23 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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