Search code examples
magentomagento-1.9

Calling a global function before a static block in category view


I've written a simple global helper function which I plan to call at the start of my category pages. It's fairly straight forward, and simply echos out the number of products in the current category along with the maximum and minimum prices. Nothing complex with it in the slightest. I'm calling the function at the start of my catalog/product/list.phtml with the simple line:

<?php  Mage::helper('module/getcatinfo')->getCatInfo();?>

The logic for my method works fine and everything is doing as it should, with one notable and annoying exception - If the category is set to 'static block and products' on the back end then the method gets called and echos it's output after the static block - I'd much prefer it to come first.

What are my options for getting my method's output onto the page before the static block? Calling my method inside a static block seems not to work in the slightest, and I'm struggling to find a solution without resorting to doing something nasty with an 'after' pseudo element.

NB: I've not included the code for the actual helper method as it's completely arbitrary to my question - It could just as well be a 'hello world' method.


Solution

  • Yeah, if you are printing it in catalog/product/list.phtml then it obviously comes after the cms block on enabling both static block & product for category. Because if you navigate to base/default/template/catalog/category/view.phtml file (on around line no.62-72)

    <?php if($this->isContentMode()): ?>
      <?php echo $this->getCmsBlockHtml() ?>
    
    <?php elseif($this->isMixedMode()): ?> <!--/ Your condition meets here both static block & product list -->
      <?php echo $this->getCmsBlockHtml() ?> <!--/ CMS Block prints here -->
      <?php echo $this->getProductListHtml() ?> <!--/ And list.phtml file to render products -->
    
    <?php else: ?>
     <?php echo $this->getProductListHtml() ?>
    <?php endif; ?>
    

    So, i guess this would help you to reorganize stuff.