How to apply custom updates to product/category pages

To apply custom updates to product/category pages in Magento 2, there are several solutions you can use depending on your specific needs. Here are a few examples:

Use Layout XML Updates
You can use Layout XML Updates to apply custom updates to product/category pages in Magento 2. This solution allows you to modify the layout of the page by adding or removing blocks, changing block attributes, and more. Here is an example of how to add a custom block to the product page:

<referenceBlock name="product.info.main">
   <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Vendor_Module::custom_block.phtml"/>
</referenceBlock>


In this example, we are adding a new block called “custom.block” to the “product.info.main” block on the product page. The block uses a custom template called “custom_block.phtml”, which should be located in the “Vendor_Module” module.

Use CMS Static Blocks
Magento 2 also allows you to create CMS static blocks and apply them to product/category pages. This solution is useful if you want to add custom content or promotions to a specific page without modifying the layout. Here is an example of how to add a CMS static block to the category page:

Go to Content > Elements > Blocks in the Magento Admin Panel.

Create a new static block with your custom content.

Go to Products > Categories and select the category you want to add the block to.

Go to the Content tab and add the following code to the “Display Settings” field:

{{block class="Magento\Cms\Block\Block" block_id="your_block_id"}}


In this example, “your_block_id” is the ID of the CMS static block you created.

Use Theme Customization
If you want to apply custom updates to multiple pages or make more extensive modifications to the layout, you can use Magento 2’s built-in theme customization features. This solution involves creating a child theme of your current theme and making modifications to the theme’s files. Here is an example of how to add a custom block to the product page using theme customization:

Create a child theme of your current theme.

Copy the “catalog_product_view.xml” file from your parent theme to your child theme’s “Magento_Catalog/layout” folder.

Add the following code to the “catalog_product_view.xml” file:

<referenceBlock name="product.info.main">
   <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Vendor_Module::custom_block.phtml"/>
</referenceBlock>


In this example, we are adding a new block called “custom.block” to the “product.info.main” block on the product page. The block uses a custom template called “custom_block.phtml”, which should be located in the “Vendor_Module” module.

These are just a few examples of how to apply custom updates to product/category pages in Magento 2. Depending on your specific needs, there may be other solutions available as well.

Scroll to Top