Magento 2: Product types and layout handles

Published on 10 Nov 2016 , edited on 22 Mar 2019

I find this something worth documenting, for the sheer scope of sources, obsolete code and articles and different semi-functional workarounds I’ve found about it. The issue? loading separate XML layout files for products in Magento 2. In my particular case all the products are Simple Products and yet I need to have different XML layouts for some of them.

So these are my options:
– Creating a new, custom, product type, extending the Simple Product
– Create custom XML handles based on either an attribute, attribute set or best; category
– Use existing XML handles

And none of them have given me a clear answer yet, so I’ll start documenting here for the sake of progress.

Creating a new product type
https://www.smartiehastheanswer.co.uk/magento2/how-to-create-a-new-product-type-in-magento2.html

Creating new XML handle
https://www.smartiehastheanswer.co.uk/magento2/adding-custom-dynamic-layout-handles-globally-in-magento2.html
https://github.com/magento/magento2/issues/102 (this is set in the Magento2 repo, but I think it’s about 1)

Development

Everything web development related, rants, snippets, tutorials, quests; it’s all there.

All categories

All tags

All posts