I just created a module that I need to test in a sample website that uses TheAdmin theme, what I need to do is to customize one of the admin pages or perhaps the layout, I tried many ways to do that with no luck :(
Any idea for doing that without introducing a new theme
You can't override MVC Views from module, however you can override it from Theme #5128
I'm utilizing the module from within an ASP.NET Core web app, let me have a look to a referenced issue
Thanks
I tried Views\OrchardCore.Admin\Admin\Index.cshtml but it doesn't work
@hishamco If you only concerned about overriding AdminDashboard then define alternate using OnDisplay events in your module and add alternate shape for it.
AdminDashboard is one thing, but also I need to change something in the admin layout
AdminDashboard is one thing, but also I need to change something in the admin layout
You can use ViewLayout property in your views to change the layout from module
I forgot about ViewLayout ;) but again I don't know why I can't override a view while I'm working on AspNetCore website
But again using ViewLayout will fit my needs if I'm able to override a view or page
If you only concerned about overriding AdminDashboard then define alternate using OnDisplay events in your module and add alternate shape for it
I'm trying to avoid shapes ;) overriding the Index view should be a replacement for that
The correct path for overriding templates is /Views/Module.Name/index.cshtml or if the module has a folder then it would be /Views/Module.Name/FolderName/index.cshtml. In your case /Views/OrchardCore.Admin/Admin/Index.cshtml should work. But you need to have this file inside a custom Admin Theme for this to work with those paths.
If you want to override OrchardCore.Admin from an extension module then your module needs to reference OrchardCore.Admin. Not sure if Views override will work though I've never tried but it should. Then the path would be the same as in the OrchardCore.Admin module in your extension module.
But you need to have this file inside a custom Admin Theme for this to work with those paths.
I don't have a custom theme, just a simple web app that reference OC
I don't think you can override a module from the base web app. You will need to create a Module that references the OrchardCore.Admin module and extend it. Then reference your custom module in the web app project.
Hmm, If I'm not wrong RCL allow us to override views from within app, unless there's something custom in OC
Simply what I wanna do it to create a bunch of modules separately and create a test web app, similar to OrchardCore.Cms.Web. Some modules needs to inject some tag helpers in TheAdmin views
The above path doesn't work either :(
Of course the modules works differently in OC because we are using tenants and different folder structure so @jtkech wrote some custom code to mimic most of the Razor folder structure logic but some might still be missing for a reason or some things could still be implemented to make it better.
May be for a reason, hope @jtkech clarify if there's an issue to override the views or layouts as normal RCL offer, meanwhile I can dig into the code, coz I remembered I did a fix for some path location to support pages
So here we have shape view template files and mvc controller view files
A shape view defined in a module1 can be overridden through the current theme (that may be a derived theme), through another module that needs a manifest dependency on module1, or through the app that behaves as a module but also as a super theme.
An mvc controller view can be overridden through the current theme as @Skrypt said in Views/{module = area}/{controller}/{action}.cshtml, but not through another module, nor through the app even it is a super theme (maybe we miss it, would be easy to add)
Note: Defining mvc controller views in OC modules is like defining them in RCL libraries but under an area folder whose name is the module assembly name. Note: Other mvc views as partial views can be shared accross modules by putting them in module Views/Shared folders.
So for example you can't override the Admin Index.cshtml mvc view from the app, but you can override the AdminDashboard shape (rendered by this mvc view) from the app, just tried it works
There is also the AdminTemplates feature to override admin shape views through the admin.
Finally as said above, would be easy to add the ability to override it from the app that behaves as a super theme but right now only to override shape views, not mvc controller views.
but not through another module, nor through the app even it is a super theme (maybe we miss it, would be easy to add)
I hope we add it, for now I will try to override the AdminDashboard, one more thing can I override the layouts too from within the app, or this is not supported yet?
There is also the AdminTemplates feature to override admin shape views through the admin.
This is working, nothing but is the override shape stored in the database instead of file system? second thing it would be nice to have all available shapes to avoid user type, I may file an issue for that
one more thing can I override the layouts too from within the app, or this is not supported yet?
Yes you can override any shape views from the app, but for the Layout, because the app is a super theme, it will override the Layout of the admin but also the Layout of the front end ;) So here better to override shape views whose name are specific to e.g. the admin.
This is working, nothing but is the override shape stored in the database instead of file system?
Yes you can also override any shape through the Templates (front end) and Admin Templates features, this only with liquid syntax and yes there are stored in the database.
Just tried with Navigation-admin.cshtml whose related template name is Navigation__admin, it works
it will override the Layout of the admin but also the Layout of the front end ;)
I see, any workaround to use it for admin views one? what if I place it in OrchardCore.Admin?
@Skrypt I reference my module with OrchardCore.Admin and place AdminDashboard.cshtml into Views\OrchardCore.Admin, but nothing overridden!! did I miss something else
AdminDashboard is a shape. Place it in Views/AdminDashboard
Just another related question is the shape will be override when the module disable? Or do I need to control it's visibility?
Just another related question is the shape will be override when the module disable?
No, only shapes of enabled modules are harvested.
Notice that the application (behaving as a module) is always enabled
Just another related question is the shape will be override when the module disable?
No, only shapes of enabled modules are harvested.
Notice that the application (behaving as a module) is always enabled
But it seems MVC views and controller actions are always available even when feature is disabled
But it seems MVC views and controller actions are always available even when feature is disabled
Normally not, with our ShellFeatureApplicationPart we only take into account controller types of enabled modules / enabled features if decorated with the [Feature()] attribute. And our mvc view location expanders only take into account enabled modules.
Let me know if you have a repro where it is not the case.
@jtkech I ended up with creating a custom theme and override the default TheAdminTheme
I'm able to override the AdminDashboard from within the new theme and web app, but
I'm unable to override the layout from the theme
If create a new shape in the custom theme, should I reference the new theme in my module in case I need to override the new one?
- I'm unable to override the layout from the theme
If your new theme is active theme then it should take Layout from that theme
Yes it is the active theme, I just drop a view named Layout in the views folder, but nothing changed
I added a UserMenu shape recently in the admin theme but I'm not able to override it from the module or a theme. Any idea how can I accomplish this task?
I added a
UserMenushape recently in the admin theme but I'm not able to override it from the module or a theme. Any idea how can I accomplish this task?
I guess you can鈥檛 override Theme shape from Module, However you can add Alternates for the shape and target the alternate from module
@ns8482e could please elaborate to point me to some docs or code, because I'm stuck for little while
Thanks
@hishamco I don't remember the doc or related issue will share if I find one.
But what I read has conclusion that -
Shapes are discovered that are placed in Views folder and in Templates. All shape have life cycle events like OnCreated, OnDisplay.
You can override shapes in following order
e.g. UserMenu.cshtml is defined in both Module and in Theme then OC will pickup from Theme.
If you want to always override UserMenu.cshtml regardless of the Theme selection then you can define it either in Template or Application.
If you still want to override shape from module ( enable/disable discovery of that shape based on module ) then define OnDisplay event in your module that adds alternate UserMenu__ModuleShape and define UserMenu-ModuleShape.cshtml in your module.
// Example code
builder.Describe("UserMenu")
.OnDisplaying(displaying =>
{
If( somecondition )
displaying.Shape.Metadata.Alternates.Add("UserMenu__ModuleShape");
}
But again, if UserMenu-ModuleShape.cshtml is present in Views in Theme then it will be picked up - which won't be there in TheAdmin theme 馃榾 in your case
Thanks @ns8482e, I will struggle to try what you are suggested before
Most helpful comment
@hishamco I don't remember the doc or related issue will share if I find one.
But what I read has conclusion that -
Shapes are discovered that are placed in
Viewsfolder and inTemplates. All shape have life cycle events likeOnCreated,OnDisplay.You can override shapes in following order
e.g.
UserMenu.cshtmlis defined in both Module and in Theme then OC will pickup from Theme.If you want to always override
UserMenu.cshtmlregardless of the Theme selection then you can define it either in Template or Application.If you still want to override shape from module ( enable/disable discovery of that shape based on module ) then define
OnDisplayevent in your module that adds alternateUserMenu__ModuleShapeand define UserMenu-ModuleShape.cshtml in your module.// Example code builder.Describe("UserMenu") .OnDisplaying(displaying => { If( somecondition ) displaying.Shape.Metadata.Alternates.Add("UserMenu__ModuleShape"); }But again, if
UserMenu-ModuleShape.cshtmlis present inViewsinThemethen it will be picked up - which won't be there inTheAdmintheme 馃榾 in your case