Hello Axel,
You can use INopDataProvider for direct access to database.
public void PopulateValues(ViewLocationExpanderContext context)
{
//no need to add the themeable view locations at all as the administration should not be themeable anyway
// if (context.AreaName?.Equals(AreaNames.ADMIN) ?? false)
// return;
context.Values[THEME_KEY] = EngineContext.Current.Resolve<IThemeContext>().GetWorkingThemeNameAsync().Result;
}
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
// {2} area , {1} controller , {0} action
if (context.Values.TryGetValue(THEME_KEY, out var theme))
{
viewLocations = new[] {
$"/Themes/{theme}/Views/{{1}}/{{0}}.cshtml",
$"/Themes/{theme}/Views/Shared/{{0}}.cshtml",
//Admin area
$"/Themes/{theme}/Areas/{{2}}/Views/{{1}}/{{0}}.cshtml",
$"/Themes/{theme}/Areas/{{2}}/Views/Shared/{{0}}.cshtml",
}
.Concat(viewLocations);
}
return viewLocations;
}
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
// {2} area , {1} controller , {0} action
if (context.Values.TryGetValue(THEME_KEY, out var theme))
{
viewLocations = new[] {
$"/Themes/{theme}/Views/{{1}}/{{0}}.cshtml",
$"/Themes/{theme}/Views/Shared/{{0}}.cshtml"
}
.Concat(viewLocations);
}
else if(context.AreaName == "Admin")
{
viewLocations = new[]{
//Admin area
$"/Areas/{{2}}/Views/{{1}}/{{0}}.cshtml",
$"/Areas/{{2}}/Views/Shared/{{0}}.cshtml"
// If you are using plugin then use below
$"/plugins/SystemName/Areas{{2}}/Views/{{1}}/{{0}}.cshtml",
$"/plugins/SystemName/Areas/{{2}}/Views/Shared/{{0}}.cshtml"
}
}
return viewLocations;
}