9

Inside of my custom module I have added the file

Vendor/Theme/view/layout/default.xml

which I am using to override a lot of the site's global templating with templates/blocks/layouts from the custom module. I am also attaching my own global styling that exist in the view/web directory in that module.

Should I be using a theme for this instead? Is there a good argument for one design pattern over the other? Eg. using app/design over app/code?

12

You can do anything you fancy, but if it is the right thing to do that is the question here.

Modules

Modules should add or change functionality of the webshop and should/could be transferred to other Magento 2 webshops. Modules can have their own layout, templates and styling and can change the general layout, templates and styling if that is necessary for the functionality of your module. Modules mostly focus on a single functionality and therefore are (relatively) small and that makes that Magento 2 webshops have many.

Modules can easily be enabled and disabled which will cause the specific functionality they add or change to appear or disappear. It shouldn't cause the whole site to change.

Themes

Themes change the global webshop's layout, templating and styling and should add or remove no functionalities. Although packaged (paid) themes could include special features, this is most often done in modules that accompany such a theme. Themes should be interchangeable, thus can be applied to any Magento 2 webshop, but also a Magento 2 webshop can switch themes easily (or have multiple for instance in a multi store setup).


So if you ask where to "override a lot of the site's global templating with templates/blocks/layouts", the answer would be in a theme.

Again, you can do anything you fancy, but if someone else would be joining or taking over development, he/she would expect site global theme changes to be in a theme and not in a module. When things are not done as expected, this slows down development and makes maintenance hard.

  • 1
    Exactly, I want to do things the right way. Appreciate the helpful answer, I'll start migrating some of these changes over to a theme. – Daniel Thompson Dec 19 '17 at 9:37
3

This answer is what I thought this could not be Magento standard

When to use theme for layout and templates and when to use Module

Theme

When you need your changes should be one place you need to show your changes should look different, in different store or website and you have multiple themes then you can do changes in theme directly

Module

when you are developing any module or extension for the requirement and you think your changes should be globally then you put layout and template in the module itself

What I suggest always make one master copy in the module and if you want to change according to your requirement then copy in the theme and make changes in templates.

This way you can solve problems like if theme is changed then also your modules files were there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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