2

I need to add my module's block between category title and product list inside the frontend category page. I guess I'll have to use an event observer, but I can't find which, and what implementation to make.

  • you do not need to observer – Amit Bera Aug 10 '14 at 14:27
1

here add the code in your layout xml file

    <catalog_category_default translate="label">
        <reference name="category.products">
        <block type="core/template" name="yourblock" as="yourblock" template="page/myblock.phtml"  output="toHtml" before="product_list" />
        </reference>
    </catalog_category_default>
    <catalog_category_layered>
        <reference name="category.products">
        <block type="core/template" name="yourblock" as="yourblock" template="page/myblock.phtml"  output="toHtml" before="product_list" />
        </reference>
    </catalog_category_layered>

And also add the code in

app/design/frontend/yourPackage/yourtemplate/template/catalog/category/view.phtml

add the below code

<?php echo $this->getChildHtml('yourblock') ?>

after end of

   <div class="page-title category-title">
    <?php if($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?>
        <a href="<?php echo $this->getRssLink() ?>" class="link-rss"><?php echo $this->__('Subscribe to RSS Feed') ?></a>
    <?php endif; ?>
    <h1><?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?></h1>
</div>

Edit: In Xml file type="core/template" is your block type and page/myblock.phtml is your phtml file location

| improve this answer | |
  • 1
    I'm making a module that is meant to be exported. If I have to modify base/default/template/catalog/category/view.phtml, it won't be exportable.. Am I wrong ? – Yonn Trimoreau Aug 10 '14 at 15:45
  • then view.phtml copy base/default/template/catalog/category/view.phtml, to yourPackage/yourtemplate/template/catalog/category/ – Amit Bera Aug 10 '14 at 16:09
  • What if someone who's using my module wants to use his own view.phtml template, for example using a theme ? – Yonn Trimoreau Aug 10 '14 at 16:18
  • then they need to <?php echo $this->getChildHtml('yourblock') ?> to his own view.phtml...otherwise not possiable.but you set your view.phtml to as category view file using<reference name="category.products"> <action method="setTemplate"><template>yourcatalog/view.phtml</template></action> </reference> – Amit Bera Aug 10 '14 at 16:24
  • So, if someone wants to use another module that personalize category view, this another module will take the step of the template ? So, not possible for magento to use 2 modules that personalize the same page ? And not possible to use a theme And a module at the same time? Sorry for those questions, but now I really don't understand why developers are using CMS systems.. – Yonn Trimoreau Aug 10 '14 at 16:30
0

Amit Bera is right, but his method can't be inside a proper module because it's rewriting Magento core files. In fact, Magento does NOT allow a block to be between category title and product list (for a module). The block has to be before category's title, and then the layout must look like this :

  <catalog_category_default>
    <reference name="content">
        <block type="modulename/blockname" name="blockname" template="template.phtml" before="-"/>
    </reference>
  </catalog_category_default>
  <catalog_category_layered>
      <reference name="content">
        <block type="modulename/blockname" name="blockname" template="template.phtml" before="-"/>
      </reference>
  </catalog_category_layered>  
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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