adminorchardcmsorchardcms-1.7orchardcms-1.8

Overriding Admin shapes in custom Orchard CMS theme


I'm doing a custom theme for Orchard CMS.

As part of client project one of the requirements is to have some extra functionality in blog admin page. This is pretty easy doing some simple changes in Parts.Blogs.BlogPost.ListAdmin.cshtml

I do not want to change the Blog source code, I would like to override that wiew in theme just like I'm doing with all the others on front end.

Following some guidelines found on orchard forum I have tried the following paths:

~/Themes/MyTheme/Views/Parts.Blogs.BlogPost.ListAdmin.cshtml
~/Themes/MyTheme/Views/Orchard.Blogs/Parts.Blogs.BlogPost.ListAdmin.cshtml
~/Themes/MyTheme/Views/Dashboard/Admin/Parts.Blogs.BlogPost.ListAdmin.cshtml

but the view is not picked up.

So, How may I override a view in my theme that will be picked up by admin dashboard instead of the default one?

Thanks


Solution

  • You need to create a theme with a project file, then add a .cs file with something like this in it:

    public class AdminOverride : IThemeSelector
    {
        public ThemeSelectorResult GetTheme(RequestContext context)
        {
            if (AdminFilter.IsApplied(context))
            {
                return new ThemeSelectorResult { Priority = 111, ThemeName = "NewAdminTheme" };
            }
    
            return null;
        }
    }
    

    Don't set this theme as current though, just enable it from the backend. You will also need to set your TheAdmin as the base theme in the Theme.txt like this:

    BaseTheme: TheAdmin