Setting template for static blocks in Magento footer

Hi!
Today I had a task to insert static blocks into footer area of Magento web page. Since there are some troubles with WYSIWYG editor and html code I opted to make it more secure for future editing so I wanted to give the static blocks their template. I’m guessing that you know how to add static block into footer area. (Hint! Add it in local.xml).
In order for static blocks to be able to have template you have to call them as a type cms/widget_block instead of cms/block. This will allow your blocks to have template because by default static blocks don’t have a template. Here’s how the footer part of my local.xml looked like:

    <reference name="footer">
      <block type="cms/widget_block" name="cms_footer_socials" template="cms/footer_area.phtml">
          <action method="setBlockId">
               <blockId>identifier</blockId>
          </action>
      </block>
    </reference>

And in my theme I added cms/footer_area.phtml that with this code. Edit it to suit your needs:

<?php 
$id = $this->getBlockId();
$block = Mage::getModel('cms/block')->load($id);
?>
<div class="block">
    <div class="title"><?php echo $block->getTitle() ?></div>
    <div class="content"><?php echo $block->getContent() ?></div>
</div>

And now my static blocks in footer area have their template 🙂 .

Published by Iva Korlevic

I'm a web programmer that started working with web pages in 2008 by programming simple HTML/CSS webpages. I finished Faculty of electrical engineering in April 2010 and started working in Inchoo in May 2010. During the time in Inchoo I worked on Zend applications, Magento stores and a few Wordpress projects. I left Inchoo in January 2012 and worked for a couple of months in Gauss Informatika as Zend teacher and team leader. In May 2012 I left Gauss Informatika and joined the team at NTH Media. For next 6 months I worked on various mobile and Wordpress projects. In the February 2013 together with MArin Blazevic I opened Proodos. I'm still continuing my work as Zend and Magento programmer. In summer 2015 I also started to work for Webbite Media GMBH and on 19th August 2015 I passed Magento Certification Exam and am now Magento Certified Developer.

Leave a comment

Your email address will not be published. Required fields are marked *