Search code examples
magentostatic-block

How do I position the Static Block defined in the Category admin page?


In the category admin under Display settings I have assigned a static block. This is displaying fine but I need to position it further down the page. I've been looking for a callback like the generic getChildHtml but for blocks.

I was also thinking that the static block code that I normally use could be change from

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block-name')->toHtml();?>

to something like this

<?php echo $this->getLayout()->createBlock('cms/block')->toHtml();?>

but alas it did not work. I could possibly be done with the local.xml file but I'm not sure how to target it.

Bit stuck so any help would be greatly appreciated


Solution

  • I've come up with a workaround. It's not ideal but it's working. Instead of using the static block option in the category page I've added the static block to the list.phtml template. I then create a variable that gets the current category name and append it to a string.

    <?php $blockid = 'category_banner_' . preg_replace('/\s+/', '', strtolower(Mage::registry('current_category')->getName())); ?>
    

    I can then call this using the standard static block call

    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($blockid)->toHtml();?>
    

    The last thing to do is make the static block and as long as it's named category_banner_CATEGORYNAME it should work fine.

    As I said it's a bit of a workaround, but for the life of me I can't work out how to reposition the one set in the admin.

    If anyone can come up with a better solution I would be eternally grateful