While working on magento themeing, we want every block to be dynamic or editable from administrator. We can add CMS block to any page or any part of page like header and footer using following ways.
1. Using XML/Layout file
Adding cms block to any page using xml/layot file is very easy. First of all you need to define block in layout xml file like:
<block type="cms/block" name="mycustomblock" as="mycustomblock">
and After that we need to call the same block in phtml file
<?php echo $this->getChildHtml('mycustomblock');?>
In above example you need to replace customBlockIdfr with your cms block idenfier in backend. I am adding custom block on product detail page, you need to change according to your need.
2. Directly in phtml file
We can also add cms block to any page by writing php code to phtml file. That’s very easy and a single line code.
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('customBlockIdfr')->toHtml(); ?>
same as above,you need to replace customBlockIdfr with your cms block idenfier in backend.
I’ll be back with few more tricks soon in new posts.