Display Static Block in Magento PHTML File

Display Static Block in Magento PHTML File

October 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Display Static Block in Magento PHTML File

Displaying Static Blocks on Product Pages in Magento

As a Magento developer, you might find yourself wanting to display static blocks created in the admin panel directly onto your product pages. This guide will walk you through the process step-by-step.

Understanding Your Current Setup

From the provided code snippets, here’s what we can deduce:

  1. You’ve added a reference to the 'right' block in your catalog.xml file.
  2. Within this reference, you’re creating a new CMS block with an ID of ‘recipes’.
  3. In your 2columns-right.phtml file, you’re trying to render both the existing right block and the newly created recipes block.

The issue seems to lie in how Magento’s layout system processes these blocks and their hierarchy.

Understanding Block Hierarchy

In Magento’s layout XML files (like catalog.xml), every <reference> tag defines a block that can contain other blocks. These child blocks are identified by their unique names.

When you call <?php echo $this->getChildHtml('right') ?> in your PHTML file, it fetches the existing right block and all its children as defined in catalog.xml or any parent layout XMLs.

However, when you use $this->getLayout()->createBlock('cms/block')->setBlockId('recipes')->toHTML();, you’re creating a new block instance independently of the layout system. This block isn’t tied to the right block hierarchy and won’t be rendered automatically.

The Correct Approach

To display a static block within an existing block (like ‘right’) on your product page, follow these steps:

  1. Define the Block in Layout XML: Make sure you’ve defined your block correctly in the layout XML file associated with your product pages (usually catalog.xml or catalog_product_view.xml).
<reference name="right">
    <block type="cms/block" name="recipes">
        <action method="setBlockId"><block_id>recipes</block_id></action>
    </block>
</reference>
  1. Call the Block in Your PHTML File: Instead of manually creating a new block instance, simply call getChildHtml() with the correct child block name.
<?php echo $this->getChildHtml('recipes') ?>
  1. Check Block Cache: Ensure that your static block is not cached or check if cache is enabled for CMS blocks in Magento’s admin panel under System > Configuration > Caching.

Conclusion

Displaying a static block on a product page requires understanding the relationship between layout XML files and PHTML templates. By properly defining the block hierarchy and calling the correct child HTML, you can successfully render your static content exactly where needed.

Catalog Themes Admin Errors

Our network