0

I'm trying to add a custom phtml file in the Product Page before Product Name/Title.

For that I've created a custom.phtml file in the path-

"...> Magento_Catalog > templates > custom.phtml".

After that I added a block in catalog_product_view.xml:

<block class="Magento\Framework\View\Element\Template" name="blockname" template="Magento_Catalog::custom.phtml"/>

What I'm missing here? please guide me to show my custom.phtml file content on product page before the product title.

  • What are the contents of custom.phtml file? – Mohit Kumar Arora Oct 30 '18 at 11:31
  • Currently its just simple HTML <h1> tag. – user54226 Oct 30 '18 at 11:47
0

I think you have missed something in your layout file (like wrong reference container etc.), which is hard to guess without seeing the code.

Please try below code in your file:

<?xml version="1.0"?>
<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\Framework\View\Element\Template" name="blockname" template="Magento_Catalog::custom.phtml" before="-"/>
        </referenceContainer>
    </body>
</page>

Refresh the cache after making the modifications.

I have checked the code in my localhost and found it working fine.

  • Is my custom.phtml file's path correct? – user54226 Oct 30 '18 at 11:48
  • Yes, the file path is fine. The problem which I could guess is the wrong container. – Mohit Kumar Arora Oct 30 '18 at 11:56
  • Here's my code <referenceContainer name="content"> <block class="Magento\Framework\View\Element\Template" name="blockname" template="Magento_Catalog::category-name.phtml"/> </referenceContainer> – user54226 Oct 30 '18 at 12:01
  • now getting this error: Magento_Catalog/templates/category-name.phtml): failed to open stream: Permission denied in – user54226 Oct 30 '18 at 12:02
  • The code seems correct. Do you have correct file permissions? – Mohit Kumar Arora Oct 30 '18 at 12:03

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.