3 Ways to use ‘Static Block’ on Magento
One drawback to using the Magento Commerce CMS is that there are too many ways to do simple things, with no guidance as to what the best approach is?
First let’s create a static block
- Go to CMS>Static Blocks, and click Add New Block
- Fill out ‘Block Title;’ the title should describe the black
- Fill out ‘Identifier;’ identifier should be url like, lowercase and no spacesi.e. your_block
- Status, disables and enables your static block, I just leave it on enabled.
Now to add it via XML
XML
Find your catalog.xml location in app > design > frontend > default > theme > layout folder. And paste the below code.
<block name="your_block_id" > <action method="setBlockId"><block_id>your_block </block_id></action> </block>
Replace the your_block with the identifier of the static block you created earlier.
Admin Panel
The most simplest and fastest way to add your static block to a page is to go to the page via admin panel and then go to the content and paste the below code in. This way you can easily move it around without having to go to the source code.
{{block type="cms/block" block_id="your_block_id"}}
Replace the your_block with the identifier of the static block you created earlier.
PHP
Find your PHTML file open your template file that contains the “toolbar” button app > design > frontend > default > theme > template > catalog > product > list > toolbar> pager. pager.phtml.
The PHTML file is just like any php page.
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_block')->toHtml(); ?>
Replace the your_block with the identifier of the static block you created earlier.
Using static block is the best because a client or myself can easily update the content within the block very easily, but adding the static block to appear on your theme although simple is not too straight forward since it can be adding in too many ways.
Good luck
Leave a Reply