3

In my /app/design/frontend/VENDORNAME/THEME/Magento_Theme/layout/default.xml I have made changes like this (changes that are effecting Magento_Catalog):

<move element="product.info.media" destination="content" before="product.info.main"/>
<referenceBlock name="product.attributes" remove="true"/>

It seems to work. The question is if it's bad in any way?

I would prefere to have a single file for all XML changes.

2 Answers 2

1

In my opinion that's not the recommended way of doing it.

I reckon instead of creating the following file:

app/design/frontend/VENDORNAME/THEME/Magento_Theme/layout/default.xml

You should create the layout file that matches the page you need to change so in your case I assume it's the product page:

app/design/frontend/VENDORNAME/THEME/Magento_Catalog/layout/catalog_product_view.xml

Putting everything in one single file in Magento 2 is not best practice in my opinion because it hides the dependencies of your code

By browsing your theme with your first file, I can't know exactly what module layout you're changing so if I'm wondering how the product.attributes got removed and I only see a Magento_Theme folder I will probably start looking somewhere else.

However, if I see a Magento_Catalog folder I'll probably think "oh that could be it".

2
  • From my understanding, the default.xml is pulled together and used on every page in Magento. So the default.xml in every module is just there for organization. And the rest of the .xml files exist for specific pages on the site. The catalog_category_view.xml will only show up on the category list page. So if you have layout updates for just that page, those would got here and the rest of the site would default to default.xml
    – circlesix
    Commented Jun 18, 2016 at 15:51
  • 1
    @circlesix totally agree with you but the OP creates a default.xml file related to the Magento_Catalog module in a Magento_Theme folder. On top of that it seems like the changes in the XML only apply to the product view page ;) Commented Jun 18, 2016 at 15:57
0

I'm fairly new to all of this myself, so there may well be better answers available, but from what I can tell, while this is certainly possible, it's not considered best practice.

As everything is now module based on the frontend, it would seem reasonable to assume that layout changes should be made by extending (or overriding) the relevant modules layout configuration using the handle as the file name for the specific module layout XML.

I may be wrong, but I believe this is best practice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.