I want to add a custom block to show some text between the product gallery and the description.

What is the best practice to do this, do I need to create my own module? and how do I override the layout XML file?

The marked yellow area is where I want my own text to be displayed.

enter image description here


3 Answers 3


There are 2 options you can put your xml file inside your theme or you can add file in your custom module. If you have theme then you don't need to create any custom module to add custom block only. But if you don't have any theme and you're using luma theme then you can create your own module and you can add files there.

1. Using theme

Create your XML file here on this location...


Content for this file is..

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
      <referenceContainer name="content">
         <block class="Magento\Framework\View\Element\Template" name="catalog.product.view.custom" template="Namespace_ModuleName::filename.phtml" before="product.info.details" />

After that you have to create one template file here



<div class="custom-block">
    <?php echo "Custom Block"; ?>

<style type="text/css">
    .custom-block {
        clear: both;
        margin-bottom: 30px;

2. Using module

Using your custom module you need to create above 2 files on below location, you can use above same content for both files.




After adding above file just run below command once

php bin/magento cache:flush


enter image description here

Hope this will help you!


Using Module


<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
      <referenceContainer name="product.info.media">
         <block class="Magento\Framework\View\Element\Template"

The best practise for this would be to add a new block reference into your catalog_product_view.xml file inside your custom theme.

To do this, you must first create your own theme (if you haven't already got one), or edit the existing files inside your theme.

To create a new theme, refer to Magento 2 documentation. It's just a few files that are required to get you started. https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/themes/theme-create.html

Inside your theme (vendor/theme/), Create the folder structure 'Magento_Catalog > layout > catalog_product_view.xml

Inside this file, add the following code:

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
      <referenceContainer name="content">
         <block name="name" template="Magento_Catalog::filename.phtml" before="product.info.details" />

Note that the 'name' of the block should be named appropriately regarding what it is and the template should be a path to the custom block contents. If the file is being referenced as the above, you must create a 'templates' folder inside the Magento_Catalog folder and then place it inside that. e.g. Magento_Catalog > templates > filename.phtml

Also notice that we are specifying before="product.info.details". this is saying that the new block should be placed before this container. You can find the container/block names of existing elements by going into the correct XML file inside: vendor/magento/module.. I'd strongly suggest looking into some Magento developer tools as many of these help you easily find container/block names, and lots of other helpful things, without the need to constantly look into the vendor folder.

  1. MgtCommerce Developer Toolbar - https://github.com/mgtcommerce/Mgt_Developertoolbar
  2. Advanced Template Hints -

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.