How to call a custom php file on magento product page

How to call a custom php file on magento product page

September 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to call a custom php file on magento product page

Customizing Magento Product Page Layout

When working with Magento, you might find that the default product page layout doesn’t quite meet your needs. By default, the getChildHtml('product_type_data') function maps to the file catalog/product/view/type/simple.phtml. However, it is possible to customize this mapping to display your own custom content.

Understanding Magento Layouts

Magento uses a modular architecture for its layouts. Each type of page (like product view) has its own XML layout file that defines where each block should be placed. The product_type_data block is defined in the catalog.xml layout update file under app/design/frontend/{package}/{theme}/layout.

Overriding Default Layouts

To override a default Magento layout, you need to create your own layout XML file and specify it in the appropriate theme’s local.xml. Here’s how you can do this:

  1. Create Your Custom File: In your theme directory (usually under app/design/frontend/{package}/{theme}), navigate to the template folder of your desired module (like catalog). Create a new XML file, for example catalog_product_view_type_simple.xml.

  2. Update the Layout: Open this new file and add the following code:

<?xml version="1.0"?>
<page layout="empty" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product_type_data">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Your_Module::your-file.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Replace Your_Module with the name of your module and your-file.phtml with the name of your custom template file.

  1. Create Your Custom Template: In the same location as your layout XML file, create a new PHP file (like your-file.phtml). This is where you can put your own custom code to display whatever content you need.

Displaying Additional Content on Product Page

Let’s say you want to add an image under “availability” that says free shipping. You can do this using the following approach:

  1. Create Your Custom Block: Create a new block type in your theme directory, for example Magento_Catalog.xml under app/design/frontend/{package}/{theme}/etc. Define a new block with an appropriate name and class.

  2. Add the Block to Layout: In your local.xml file (or a layout update XML like catalog_product_view_type_simple.xml), add a reference to your custom block:

<referenceBlock name="product.info.additional">
    <block type="Your_Module/your-block" before="-" template="Your_Module::your-file.phtml"/>
</referenceBlock>
  1. Create Your Custom Template: In the template folder of your module, create a new PHP file (your-file.phtml) where you can add the image and any other content you need.

Conclusion

Customizing Magento product page layouts allows for greater flexibility in displaying additional content like images or custom messages under specific sections. By creating your own layout files and referencing them appropriately, you can easily override the default behavior to meet your specific needs.

Remember that proper theme inheritance is key when working with Magento. Always ensure you’re editing the correct theme level (parent or child) based on your project requirements.

For more detailed information on Magento layout and template customization, I recommend checking out our Magento Theme Development Guide. It provides a comprehensive walkthrough of the process with practical examples.

Catalog Extensions Themes Configuration

Our network