Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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()
share|improve this answer
1  
Thanks for the quick answer. This works great! –  tecjam Jun 6 at 8:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.