3

I am new to Magento .

I have a problem while trying to add a block to ‘category.products’, but if I try to add a block to ‘content’, it works perfect. I searched through Stack Exchange, but I couldn’t find any solution for my problem.

In my layout file (located at app/design/frontend/default/hookahs/layout/webwhales/seoblock.xml), I have the following:

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="category.products">
            <block type="webwhales_variousmodule/catalog_categoryseo" name="webwhales_seoblock" />
        </reference>
    </default>
</layout>

My layout file is being loaded, because I can remove a sidebar for example.

The config file looks like this:

<?xml version="1.0" ?>
<!-- Root node for Magento configuration files -->
<config>
    <modules>
        <WebWhales_VariousModule>
            <version>0.1.0</version>
        </WebWhales_VariousModule>
    </modules>
    <global>
        <blocks>
            <webwhales_variousmodule>
                <class>WebWhales_VariousModule_Block</class>
            </webwhales_variousmodule>
        </blocks>
        <models>
            <webwhales_variousmodule>
                <class>WebWhales_VariousModule_Model</class>
            </webwhales_variousmodule>
        </models>
    </global>
    <frontend>
        <layout>
            <updates>
                <webwhales_variousmodule>
                    <file>webwhales/seoblock.xml</file>
                </webwhales_variousmodule>
            </updates>
        </layout>
    </frontend>
</config>

My block class is located at app/code/local/WebWhales/VariousModule/Block/Catalog/Categoryseo.php and has the following content:

<?php
    class WebWhales_VariousModule_Block_Catalog_Categoryseo extends Mage_Core_Block_Template {
        public function __construct() {
            parent::__construct();
            $this->setTemplate( 'webwhales/seoblock.phtml' );
        }
    }

Right now I have no clue what the problem is or how to solve it. When I change <reference name="category.products"> to <reference name="content"> it works, but my code isn't loaded at the right place; it has to be loaded at the top of category.products.

I have also tried to change <default> to <catalog_category_default> or <catalog_category_layered>, but that doesn't make a difference either.

3
  • May be you have place seoblock.xml at wrong location. If Checking this,you can put this file at app/design/frontend/base/default/layout/webwhales/seoblock.xml from app/design/frontend/default/hookahs/layout/webwhales/seoblock.xml
    – Amit Bera
    Feb 10 '16 at 9:58
  • What's the content of you catalog/category/view.phtml template ? Feb 10 '16 at 10:01
  • @AmitBera my layout file still get loaded because i tried to remove 'left' and 'right' blocks and it got removed. @DigitalPianism i have <?php echo $this->getChildHtml('webwhales_seoblock');?> added in that file, but it doesn't work.
    – klict
    Feb 10 '16 at 10:14
0

category.products template file is view.phtml ( app/design/frontend/Your_Package/Your_Theme/template/catalog/category).

Here the child block does not automatically render.You need to call the child block by

echo $this->getChildHtml('webwhales_seoblock');
6
  • thanks for your answer but i have tried it but it doens't work.
    – klict
    Feb 10 '16 at 10:09
  • Chnage handler tp catalog_category_view
    – Amit Bera
    Feb 10 '16 at 10:11
  • what do you mean by handler?
    – klict
    Feb 10 '16 at 10:15
  • just change '<default>' to '< catalog_category_view>'
    – Amit Bera
    Feb 10 '16 at 10:15
  • 1
    Thanks for your answer, i changed the handler to 'catalog_category_layered' and it worked
    – klict
    Feb 10 '16 at 11:38

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.