mtrueblood
mtrueblood

Reputation: 414

Need to remove the title from a specific magento category page

The problem

I need to remove the category name or title from specific non-product category pages but can't find the reference or block names to remove it with layout updates. I have already found the code that I could override and comment out to remove the title from every category page but that won't work since I need the title on most category pages.

What I'm trying to do

In the past I've been able to turn on the template path hints with block names, spend a second researching and found a great way to remove a block. This is the kind of code I have used before:

<reference name="Mage_Page_Block_Html_Breadcrumbs">
   <remove name="breadcrumbs"/>
</reference>

TL;DR

I just need a simple way to remove the category title name from specific categories. If my idea about update xml is junk I'll take any suggestions. Thanks for any help.

Upvotes: 0

Views: 1374

Answers (1)

Christoffer Bubach
Christoffer Bubach

Reputation: 1686

I'd start by creating a custom module, overriding the Mage_Catalog_Block_Category_View block and doing something like this:

In app/local/Yournamespace/Titlemodule/etc/config.xml

<config>
<!-- .... -->
    <global>
        <blocks>
            <titlemodule>
                <class>Yournamespace_Titlemodule_Block</class>
            </titlemodule>
            <catalog>
                <rewrite>
                    <product_view>Yournamespace_Titlemodule_Block_Category_View</product_view>
                </rewrite>
            </catalog>
        </blocks>
        <!-- ... -->
</config>

and in app/local/Yournamespace/Titlemodule/Block/Category/View.php

class Yournamespace_Titlemodule_Block_Category_View extends Mage_Catalog_Block_Category_View
{
    protected function _prepareLayout()
    {
        parent::_prepareLayout();
        $category  = $this->getCurrentCategory();  // if needed
        $headBlock = $this->getLayout()->getBlock('head');
        // custom logic here
        $headBlock->setTitle($this->__('New title, or none'));
        return $this;
    }
}

It will give you plenty of possibilities running custom logic before manipulating any blocks on the page.

Upvotes: 1

Related Questions