1

I want move static block landing in Category. I found code in file

/app/design/frontend/base/default/template/catalog/category/view.phtml

<?php elseif($this->isMixedMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>
<?php echo $this->getProductListHtml() ?>

I tried copy or move <?php echo $this->getCmsBlockHtml() ?> in file 2columns-left.phtml but it does not work.

2
  • What exactly is not working? Please update your question with errors and what you have tried so far Commented Oct 28, 2015 at 14:28
  • Reviced. I get error if I move all conditional instructions. Commented Oct 28, 2015 at 14:39

2 Answers 2

1

Add bellow code in file 2columns-left.phtml

<?php if($currentCategory = Mage::registry('current_category')):?>
                <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($currentCategory->getLandingPage())->toHtml();     
?><?php endif;?>
1
  • This one works immediately. +1. :)
    – jehzlau
    Commented Aug 6, 2019 at 5:16
1

The problem is you cannot use those methods outside of the category view.phtml file.

If you want to get a categories static block content outside of this file you can use the following I based this on the answer given here by Rajeev - how to get cms block value from display settings of a category

Create a new template block add the following to your local xml

    <default>
        <reference name="root">
            <block type="core/template" name="category_static_block" template="page/html/category_static_block.phtml"/>
        </reference>
    </default>

Add the code below into your block

        <?php
        if (Mage::registry('current_category')):

            //get current category id
            $categoryId = Mage::registry('current_category')->getId();
            //load current category model
            $category = Mage::getModel('catalog/category')
                    ->setStoreId(Mage::app()->getStore()->getId())
                    ->load($categoryId);

            $mode = $category->getDisplayMode();
            //display mode = PAGE means, that category has a static block
            if ($mode == 'PAGE' || $mode == 'PRODUCTS_AND_PAGE'):
                //get static block id
                $page = $category->getLandingPage();

                //cms block
                $cms_block = Mage::getModel('cms/block')->load($page);

                //parse template to convert {{fields}}
                //from http://stackoverflow.com/a/5413698/156388
                $helper = Mage::helper('cms');
                $processor = $helper->getPageTemplateProcessor();
                $content = $processor->filter($cms_block->getContent());
                echo $content;

            endif;
        endif;
        ?>

And then echo this block out within your page template file:

<?php echo $this->getChildHtml('category_static_block');?>
9
  • I copied your code to 2columns-left.phtml and clear cache but it still does not work. Commented Oct 29, 2015 at 8:54
  • Just realised I am using the code above in a core/template block not within a page template. Ill have a look and update my answer
    – Bobadevv
    Commented Oct 29, 2015 at 9:10
  • Ive updated my answer can you try the above and let me know if this works for you
    – Bobadevv
    Commented Oct 29, 2015 at 10:57
  • code in local.xml put middle <config> ? Commented Oct 29, 2015 at 11:59
  • no create a file local.xml and put this within your theme files under app/design/frontend/yourpackage/yourtheme/layout
    – Bobadevv
    Commented Oct 29, 2015 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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