Overriding shape template for specific module from theme

Topics: Writing themes
Developer
Apr 24, 2012 at 5:38 PM

Evidences from the localization of TheThemeMachine theme suggest that there is the ability to override shape templates (or here rather: views) for a specific module. Look for "Orchard.Tags" on the linked page: it seems that once the Home/Search.cshtml view of Orchard.Tags was overridden. This does work now too for simple views, but for other templates (e.g. display shape templates) it seems not to. Is this intended?

Coordinator
Apr 24, 2012 at 5:49 PM

It has always worked, by design. All templates can be overridden from themes. What did you try that didn't work?

Developer
Apr 24, 2012 at 5:52 PM
Edited Apr 24, 2012 at 5:54 PM

Well it seems it is and the answer for the question "Where can I place my override then if I want it to be module-specific?" came from an unexpected helper, from the InvalidOperationException thrown when the system can't find a template :-). It tells where it searched, so it seems that the example with Tags works because it has the controller name in its path too. So e.g. this will work too:

/Themes/MyTheme/Views/MyModule/MyController/DisplayTemplates/Whatever/MyTemplate.cshtml

or also this, but this is not module-specific:

/Themes/MyTheme/Views/DisplayTemplates/Whatever/MyTemplate.cshtml

What I originally wanted, following the logic was this:

/Themes/MyTheme/Views/MyModule/DisplayTemplates/Whatever/MyTemplate.cshtml

All considering that the original template is under:

/Modules/MyModule/Views/DisplayTemplates/Whatever/MyTemplate.cshtml

Edit: thanks Bertrand, the above did the trick.