Anthony
Anthony

Reputation: 2411

Specify Category specific layout updates without using Magento's administration dashboard

Is there a way to specify a layout update for a specific category (e.g. using category ID) without having to use the administration dashboard, and setting a [Custom Design > Custom Layout Update].

I am sure I can create a module that looks for a category ID and switches the layout based upon that, but I was curious if there was a naming or some other type of convention for layout files that allows for this type of granular control since Zend Framwork sometimes allows such naming conventions.

Also maybe within the catalog.xml file itself there are additional "layouts" that allow such granularity, something more specific than <catalog_category_layered />

Upvotes: 5

Views: 4015

Answers (2)

Alana Storm
Alana Storm

Reputation: 166086

In a standard Magento install (1.4.2, but it should apply to the rest), Magento issues the following Layout handles (handles tell Magento which Layout Update XML Fragments to load from the Package Layout)

<default />
<catalog_category_layered_nochildren />
<STORE_default />
<THEME_frontend_default_default />
<catalog_category_view />
<catalog_category_layered />
<CATEGORY_4 />
<customer_logged_out />

The following layout handle

<CATEGORY_4 />

is generated based on the ID for a category. This means you should be able to add something like the following to your local.xml, or to a custom layout XML file added via a custom module

<layouts>
    <CATEGORY_4>
        <!-- your UPDATE xml here -->
    </CATEGORY_4>
</layouts>

Upvotes: 16

Joe Mastey
Joe Mastey

Reputation: 27119

When visiting a catalog category, Magento loads a handle for CATEGORY_${ID}, which you can use to do exactly what you are asking.

Upvotes: 2

Related Questions