4

I'm trying to move the static CMS block from the category view into the sidebar. In my themename/template/catalog/category/view.phtml it is called with

$this->getCmsBlockHtml()

Since it's defined as

 /**
   * Retrieve current category model object
   *
   * @return Mage_Catalog_Model_Category
   */
  public function getCurrentCategory()
  {
      if (!$this->hasData('current_category')) {
          $this->setData('current_category', Mage::registry('current_category'));
      }
      return $this->getData('current_category');
  }

  public function getCmsBlockHtml()
  {
      if (!$this->getData('cms_block_html')) {
          $html = $this->getLayout()->createBlock('cms/block')
              ->setBlockId($this->getCurrentCategory()->getLandingPage())
              ->toHtml();
          $this->setData('cms_block_html', $html);
      }
      return $this->getData('cms_block_html');
  }

I've tried adding this:

echo $this->getLayout()->createBlock('cms/block')->setBlockId(   $this->getCurrentCategory()->getLandingPage()    )->toHtml()

into my themename/template/callout/left-col.phtml file, but this throws errors.

How do I make it work?

tecjam
  • 4,033
  • 3
  • 27
  • 48

1 Answers1

8

Well, the getCurrentCategory() method is defined in the category view block Mage_Catalog_Block_Category_View, thus the left-col.phtml template doesn't have any refference to it. So instead of calling getCurrentCategory() method to get the category, you can get it from the registry: Mage::registry('current_category')

So, you can try changing your code to this:

echo $this->getLayout()->createBlock('cms/block')->setBlockId( Mage::registry('current_category')->getLandingPage() )->toHtml()
Alex Dinca
  • 2,147
  • 15
  • 16