Magento: template based on attribute set

Magento: template based on attribute set

August 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: template based on attribute set

Creating Different Product Views Based on Attribute Set in Magento

Introduction

In Magento, you can create distinct product views based on the attribute set that the product belongs to. This allows for customized product displays depending upon the specific attributes of your products.

Understanding Magento’s Default Behavior

By default, Magento does not provide a built-in way to create different product views based solely on the attribute set. However, with some customization and configuration, this is definitely achievable.

Current Implementation Status

In your current setup, you have made significant progress towards achieving your goal:

  1. You’ve added the following line of code in the Mage_Catalog_ProductController:
$update->addHandle('PRODUCT_ATTRIBUTE_SET_ID_'.$product->getAttributeSetId());
  1. In your catalog.xml file, you have defined a new layout handle for the Book attribute set and linked it to a custom template (book.phtml).

  2. You’ve created a new template file at catalog/product/view/attribute_set/book.phtml.

Why the Current Setup Isn’t Working

The issue lies in how Magento processes layout handles. The handling of your custom attribute set ID is not being recognized because Magento doesn’t have it built into its core logic.

The default Magento functionality only recognizes layout handles based on product types (PRODUCT_TYPE_), specific products (PRODUCT_), and categories (CATALOG_CATEGORY_ID_).

A Pragmatic Solution

Since the core Magento system doesn’t support attribute set-based layouts out-of-the-box, you’ll need to create a custom module to implement this feature.

Here’s a high-level approach:

  1. Create a Custom Module: In your app/code/local directory, create a new folder for your module (e.g., ProductAttributeSetLayout).

  2. Override the Layout XML Generation: Override the core layout generation process in your custom module to include your attribute set-based layout handles.

  3. Process Attribute Set ID in Layout XML: In your overridden code, process the attribute set ID and generate a corresponding layout handle (e.g., PRODUCT_ATTRIBUTE_SET_ID_9).

  4. Add Custom Template Reference: In your custom layout XML file (catalog.xml), add a reference to your new template for this specific attribute set.

  5. Flush Layout Caches: After making these changes, ensure you flush the Magento layout and block HTML caches from the admin panel (System > Cache Management).

Conclusion

While Magento itself doesn’t provide direct support for attribute set-based product views, it is entirely possible to achieve this through custom module development.

This approach ensures that your e-commerce platform remains highly flexible while maintaining the performance benefits of a robust caching system.

Remember to follow the best practices when extending or overriding core Magento functionality. Always keep your code organized and maintain proper documentation.

For more detailed guidance on Magento customization, feel free to explore our resources at Laravel Company. We provide comprehensive tutorials and expert consulting services for all your e-commerce needs.

Catalog Themes Configuration Errors

Our network