|Search the Knowledgebase
||Browse by Category
|Magento: Adding CMS Static Blocks to Templates
CMS static blocks are used to create customized content in a Magento store. In order to display a new CMS block, some code needs to be added to the stores custom layout. This article will describe two processes for accomplishing this these tasks.
24th of December, 2014
|User Opinions (14 votes)
Thank you for rating this answer.
Define CMS Static Block
The first step is to create the necessary static blocks under CMS -> Static Blocks.
Remember to write down the identifiers used when creating the static block.
Locate Template/Layout Files
Locating the template and layout files to update can be a bit tricky. Enabling "Template Path Hints" is an efficient way to track these files down:
Viewing your store in another tab/browser will now show you which templates are used to render various sections of the page. You'll want to note the full path to the template (phtml file).
- Navigate to System -> Configuration
- Change 'Current Configuration Scope' to the store view
- Under the Advanced section of the configuration menu, select Developer
- Expand 'Developer Client Restrictions' and enter your IP address (this will insure that template path hints are not displayed to others)
- Expand 'Debug' and set 'Template Path Hints' to Yes
- Save Configuration
Layout/Template files will be located in one or more of the following directory paths:
Understanding Theme Fall-Back System
Prior to updating any template/layout files, it is important to understand
how the template fall-back system works in Magento.
These articles are a good starting point:
When modifying the template (or layout file), we should consider whether the location of the file needs to change. If the template to be modified is located in the default folder (e.g.
app/design/frontend/your_package/default/template) for your theme or the
base folder (e.g. app/design/frontend/base/default/template), you
should first make a copy of the template and place it in your custom
package/theme folder (e.g.
This is important for two reasons:
1. Insures the custom version of the template is rendered.
2. Prevents customizations from being overwritten by upgrades.
Modify Template/Layout Files
The next step is to add the necessary code in your templates to call
these blocks. The method used depends on the type of CMS
- CMS blocks which are to be displayed in multiple places throughout the
site (i.e. on more than one template), we would use the XML method.
- CMS blocks which are to be displayed in a specific location, we would
likely use the template method (easier).
The XML method requires updating the layout file (XML) and template file (phtml).
- Download the relevant XML and phtml files via FTP
- Prior to editing, make backup copies of each file (local or remote)
- In the XML file, locate the section where the block should appear and copy/paste the following code (change 'your_identifier' to the one associated with your CMS static block):
<block type="cms/block" name="your_identifier" before="-">
- In the PHTML file, copy/Paste the code below in the desired location (change 'your_identifier' to the one associated with your CMS static block):
<?php echo $this->getChildHtml('your_identifier'); ?>
- Upload the modified files via FTP (overwrite if applicable, otherwise set in proper location).
- Clear all caches
The template method only requires updating the template file (phtml).
- Download the relevant phtml file via FTP
- Prior to editing, make a backup copy of the template (local or remote)
- Copy/Paste the code below in the desired location within the phtml file (change 'your_identifier' to the one associated with your CMS static block):
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_identifier')->toHtml() ?>
- Save the now customized phtml file and upload it via FTP (overwrite if applicable).
- Clear all caches
are critical in Magento. If a template was originally copied from
'app/design/frontend/base/default/template/customer/account/', then the
modified version should be uploaded to
Note that it may be necessary to create the required folder structure in your themes directory.
templates are modified in 'app/design/frontend/base/default' or
'app/design/frontend/your_theme/default', they will be lost if/when
either are upgraded.
No related articles were found.
No attachments were found.