Magento 1 provides a flexible CMS system that allows store administrators to create reusable content through static blocks. These blocks can contain HTML, text, images, links, banners, promotional content, or other frontend elements that you may want to display in different areas of your store.
Sometimes, however, you need to display a Magento CMS static block directly inside a .phtml template file rather than inserting it through a CMS page or layout XML. Magento provides a simple way to do this using the cms/block block type.
What Is a Magento Static Block?
A static block is a reusable piece of CMS content that can be managed from the Magento administration panel. Instead of hard-coding the same HTML into multiple template files, you can create the content once in the admin panel and load it wherever it is required.
For example, a static block can be used for:
- Footer links and information
- Homepage promotional banners
- Sidebar content
- Customer service information
- Shipping and delivery messages
- Store-specific promotional content
- Reusable marketing sections
- Custom HTML content
This approach also makes content easier for non-developers to update because the text and HTML can be changed from Magento's CMS interface without modifying the template file.
How to Create a Static Block in Magento 1
Before rendering a static block in a PHTML file, you first need to create the block from the Magento administration panel.
- Log in to the Magento Admin Panel.
- Go to CMS → Static Blocks.
- Click Add New Block.
- Enter a title for the block.
- Enter a unique Identifier.
- Set the block to Enabled.
- Add your content.
- Save the block.
The identifier is especially important because it is the value you use when loading the block from your PHTML template. For example, if the identifier is footer_links, you can use that identifier in your PHP code.
Render a Magento Static Block in a PHTML File
Once the static block has been created, you can render it directly from a PHTML template using the following code:
<?phpecho $this->getLayout() ->createBlock('cms/block') ->setBlockId('footer_links') ->toHtml();?>
Replace footer_links with the identifier of your own CMS static block.
The code creates a Magento CMS block, assigns the requested static block identifier, and outputs the resulting HTML. This is a commonly used approach for displaying CMS blocks directly from Magento 1 template files.
How the Code Works
It is useful to understand each part of the statement before using it in a custom Magento module or theme.
1. Get the Magento Layout
$this->getLayout()
The getLayout() method gives the current layout object. Magento's layout system is responsible for creating and organizing blocks that are eventually rendered on the frontend.
2. Create the CMS Block
->createBlock('cms/block')
The cms/block alias tells Magento that you want to create a CMS block instance.
3. Specify the Static Block Identifier
->setBlockId('footer_links')
The setBlockId() method specifies which CMS static block should be loaded. The value must match the block's identifier configured in the Magento Admin Panel.
4. Render the Block as HTML
->toHtml()
Finally, toHtml() renders the block and returns its HTML output, which is then displayed by echo.
Complete Example
Suppose you created a static block with the following identifier:
homepage_promotion
You can render it inside a PHTML file like this:
<?phpecho $this->getLayout() ->createBlock('cms/block') ->setBlockId('homepage_promotion') ->toHtml();?>
Magento will load the CMS block identified by homepage_promotion and output its content at that location in the template.
Using a Static Block in a Footer
A common use case is adding reusable content to a footer template such as footer.phtml.
<div class="footer-custom-content"> <?php echo $this->getLayout() ->createBlock('cms/block') ->setBlockId('footer_links') ->toHtml(); ?></div>
This allows administrators to update the footer content through Magento CMS rather than requiring a developer to edit the PHTML template each time.
Alternative: Add the Static Block Through Layout XML
For blocks that are part of your theme's normal layout structure, you can also define the CMS block through Magento layout XML and then render it from the template.
<block type="cms/block" name="footer_links_block" as="footer_links_block"> <action method="setBlockId"> <block_id>footer_links</block_id> </action></block>
You can then access the child block from a suitable PHTML template using:
<?php echo $this->getChildHtml('footer_links_block'); ?>
The layout XML approach can be preferable when the block is a permanent part of the page layout and you want Magento's layout system to control where the block is created. Magento developers commonly use both direct PHTML rendering and layout XML depending on the use case.
Render a Static Block in a CMS Page
If you are working inside a CMS page or another CMS-managed content area rather than a PHTML template, Magento also supports a CMS block directive.
{{block type="cms/block" block_id="footer_links"}}
Here, footer_links is again the identifier of the static block you want to display. This method is useful when the content is being managed directly through Magento's CMS rather than a theme template.
PHTML vs Layout XML vs CMS Directive
Choosing the right method depends on where you need the content.
| Method | Best Use Case |
|---|---|
| PHTML | When you need to render a static block directly inside a template. |
| Layout XML | When the block should be part of Magento's layout structure. |
| CMS Directive | When inserting a block into a CMS page or CMS-managed content. |
Common Problems When a Static Block Does Not Display
1. Incorrect Block Identifier
The most common problem is using the block title instead of its identifier. Make sure the value passed to setBlockId() exactly matches the identifier configured under CMS → Static Blocks.
2. Static Block Is Disabled
Check that the CMS block is enabled. A disabled block will not be displayed as expected.
3. Store View Assignment
If your Magento installation has multiple store views, check that the CMS block is assigned to the appropriate store view. A block may exist in the admin panel but not appear on the frontend if it is unavailable for the current store view.
4. Magento Cache
If you have recently created or modified the CMS block and the changes are not appearing, clear or refresh the relevant Magento cache types and reload the page. Cache-related issues are a common troubleshooting step when CMS content appears outdated.
5. Check the PHTML Template
Make sure you are editing the template that is actually being used by the current layout and store view. Magento 1 themes can contain multiple template overrides, so changing the wrong PHTML file may have no visible effect.
Best Practices for Magento 1 CMS Blocks
- Use descriptive and unique block identifiers.
- Avoid duplicating the same HTML across multiple PHTML templates.
- Use CMS blocks for content that administrators need to update regularly.
- Use layout XML when a block is part of a reusable page layout structure.
- Keep large pieces of reusable content inside CMS blocks rather than hard-coding them into templates.
- Clear Magento cache after making changes if the updated content does not appear immediately.
- Test CMS block visibility across the relevant store views in a multi-store installation.
Why Use CMS Static Blocks?
Using Magento static blocks can reduce unnecessary duplication and make content management easier. Instead of placing the same promotional message, footer information, or marketing HTML into several templates, you can maintain the content in one CMS block and render it wherever needed.
This separation between content and template code is particularly useful for Magento stores where marketing or content teams need to make frequent changes without modifying PHP template files.
Frequently Asked Questions
How do I call a static block in a Magento 1 PHTML file?
Use Magento's layout object to create a cms/block and provide the CMS block identifier:
<?php echo $this->getLayout()->createBlock('cms/block') ->setBlockId('your_block_identifier') ->toHtml(); ?>
Where can I find the Magento static block identifier?
In Magento 1 Admin, go to CMS → Static Blocks, open the block, and check its Identifier field. Use that exact identifier in setBlockId().
Can I display a Magento CMS block in any PHTML file?
Yes, the direct createBlock('cms/block') approach can be used in a PHTML template where the Magento layout object is available. The exact template location depends on your theme and layout configuration.
Why is my Magento static block not showing?
Check the block identifier, enabled status, store-view assignment, template being used, and Magento cache. These are common causes when a CMS block does not appear on the frontend.
Can I use a static block in multiple places?
Yes. A major benefit of CMS static blocks is that the same reusable content can be rendered in different areas of a Magento store instead of duplicating the HTML in multiple templates.
Should I use PHTML or layout XML to load a CMS block?
Use PHTML when you need to render the block directly at a specific point in a template. Layout XML is often a better choice when the CMS block should be managed as part of Magento's page layout and block hierarchy.
Conclusion
Rendering a Magento 1 static block from a PHTML file is straightforward using the cms/block block type and the block's unique identifier. The approach is useful for adding reusable footer content, promotional sections, banners, sidebar elements, and other CMS-managed content without hard-coding everything into your theme templates.
For larger Magento projects, choosing between PHTML, layout XML, and CMS directives based on the purpose of the content can also make your codebase easier to maintain.
Need Help With Your Magento Store?
Working with a legacy Magento 1 store can become challenging when custom themes, extensions, outdated code, and performance issues start to add up. If you need help maintaining or improving your Magento store, our development team can help with custom development, legacy code improvements, integrations, and ongoing technical support.
Have a Magento project that needs expert attention? Contact our development team to discuss your requirements and find the right solution for your store.