Can a module install a theme?

Topics: Writing modules, Writing themes
Aug 2, 2015 at 6:04 AM
Can I write a module, that brings/installs a theme? Or are modules and themes to be considered "separate"?
Aug 3, 2015 at 7:37 AM
A module is considered to be an independent part of functionality. A module should never depent on a theme.
The other way around is possible though, a theme can depent on a module.

Is your module's functionality dependant on the theme? Or do you just want to provide links to install themes through your module?
Aug 4, 2015 at 5:19 AM
Thank you for your anwser.

I am new to Orchard and its overall architecture. I have a customer that wants a CMS with its own, individual design, and also some individual business functionality/content types.

My first thought was to pack everything into a new Orchard module, including the theme. But now I see that this is wrong.

So, if I understand you correctly, I will finally have to deliver 2 components seperately, the module and a theme.
Aug 4, 2015 at 7:00 AM
Edited Aug 4, 2015 at 7:01 AM
In theory a theme can also be made from within a module, but following orchard's (best) practices you would indeed need a module for the functionality and a theme for the looks and feels.
Another reason why it would be a bad idea is that a theme always gets precedence over a module. So if you override views in your modules (for the theming), then the enabled theme can override it again and use its own views. Also, if you decide to use another theme, you can just switch between the themes without touching the module.

The way to go is to create a module with the functionality and 'ordinary' views (as basic as possible), and create a theme to customize those views (and other views probably).
Aug 5, 2015 at 9:47 AM
Edited Aug 5, 2015 at 9:50 AM
You always need to have some theme, but the way you split code between the two highly depends on your scenario. The rule of thumb is not to mix UI logic with business logic, which applies not only to Orchard.

Technically speaking, Modules and Themes are considered similar thing in Orchard - the "extensions". There are a few differences though, which @sanderg summarized the majority of already (the precedence when it comes to overriding views). You may put everything into one bag, the theme, but the question is - do you want to?

So this is clearly an architectural thing and you need to answer a few questions:
  • Is the code you put in a theme related to theming? If so - put in the theme - if not, it should go into a module
  • Is this particular piece of functionality you're adding reusable? Especially if you plan on switching themes at some point? If so - put it in a module.
  • I need to add some UI for some feature. Should I place it in a theme? Answer is - both. The module that provides this particular feature should provide some basic, working UI that gets things done (if you'd ever want to switch themes and not get approached by YSOD), like views for your controllers etc. My point is that even without a theme your application should be usable. The theme should contain all the fancier, final stuff.
  • I need to do some really custom stuff in a custom controller and I need that themed! Same thing as above, but I wanted to surface this separately as this is particularly useful when you're doing theming over a complex system containing custom controllers (like a normal ASP.NET MVC app does). First, put everything in your module and provide the basic views there, as usual. Then, in your theme, you can override any view from the whole app by putting the new ones under /<My.ModuleName</<Controller name>/<MyView.cshtml> in the theme.
Finally, to answer your initial question - yes, those two should be considered separate.
Marked as answer by mcmcod120 on 8/9/2015 at 5:29 AM