Customizing Multiple Category Templates in Magento
In Magento, adding multiple custom templates for different shop categories can be achieved by properly configuring your local.xml file. This process allows you to create distinct layouts for each category page while keeping the codebase clean and organized.
Understanding the Layout XML Structure
The layout XML structure defines how a page is rendered, including which blocks are added and their positions on the page. The root element of this structure is <layouts>, inside which you define your custom templates under child elements like <catalog_category_layered>.
<layouts>
<catalog_category_layered>
<!-- Custom template configuration goes here -->
</catalog_category_layered>
</layouts>
Adding Multiple Category Templates
To create multiple category templates, you’ll need to add new child elements inside the <layouts> section of your local.xml file. Each element represents a unique template with its own layout and style.
Here’s an example of adding two custom category templates:
<page>
<layouts>
<homepage>
<label>Home Page</label>
<template>page/1column-home.phtml</template>
</homepage>
<shop1_category_layered>
<label>Shop 1 Category Layered</label>
<template>page/shop1/category-layered.phtml</template>
</shop1_category_layered>
<shop2_category_layered>
<label>Shop 2 Category Layered</label>
<template>page/shop2/category-layered.phtml</template>
</shop2_category_layered>
</layouts>
</page>
In this example, we’ve added two new templates: shop1_category_layered and shop2_category_layered. Each template is associated with a unique file (category-layered.phtml) specific to the respective shop category.
Important: Make sure that each custom template file exists in its designated location. For instance, page/shop1/category-layered.phtml should be located under the page folder of your theme directory for Shop 1.
Applying Templates to Specific Categories
To apply these templates to your category pages, you’ll need to update the layout handles assigned to those categories in the Magento admin interface. Go to CMS > Pages and select the specific category page you want to modify.
Under the Design Layout Update XML field, add a new handle for each custom template:
<reference name="root">
<action method="setTemplate">
<template>page/shop1/category-layered.phtml</template>
</action>
</reference>
Replace category-layered.phtml with the actual filename of your desired custom template.
Conclusion
Adding multiple custom category templates to Magento involves proper configuration of your local.xml file and careful assignment of layout handles in the admin interface. By following this approach, you can create distinct layouts for each shop’s sub-homepage while maintaining a clean codebase.
Remember that each template should have its unique filename located under the appropriate theme directory. This ensures that your custom designs are applied correctly to the respective category pages.
For further guidance on advanced Magento layout customization and best practices, consider reading our in-depth tutorials at Laravel Company.
Happy coding!