You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made 2 Modules for our shop.
First one (MyCodeModule) is for Controllers, Domain, WebApi etc and the second one is for solely Theming (Theme WBlue).
What I now encountered (after having a typo) is this:
InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Modules/MyCodeModule/Views/Spareparts/Index.cshtml
/Modules/MyCodeModule/Views/Shared/Index.cshtml
/Themes/WBlue/Views/Spareparts/Index.cshtml
/Themes/WBlue/Views/Shared/Index.cshtml
/Themes/Flex/Views/Spareparts/Index.cshtml
/Themes/Flex/Views/Shared/Index.cshtml
/Views/Spareparts/Index.cshtml
/Views/Shared/Index.cshtml
My Question:
Shouldn't the MyCodeModule paths be checked after the themes?
Because at the moment I can not theme a controller/cshtml defined in MyCodeModule in my WBlue theme. Although the _custom.css of the theme is used.
It doesn't pose a problem for me since both modules are under my control but in other constellations one might want to be able to theme a view of another module.
Btw, I did set Order and DepdendsOn in the module.json properly so the theme depends on the code module. But the code in the IViewLocationExpanders doesn't account for any dependency sorting.
The text was updated successfully, but these errors were encountered:
This works for me in the ModuleViewLocationExpander:
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
if (context.Values.TryGetValue(ParamKey, out var moduleName))
{
var module = _moduleCatalog.GetModuleByName(moduleName);
if (module != null)
{
// Check if there are dependencies for this module in the current theme module
if (context.Values.TryGetValue(ThemeKey, out var themeName))
{
var themeModule = _moduleCatalog.Modules.FirstOrDefault(x => x.Theme == themeName);
if (themeModule != null && themeModule.DependsOn.Contains(module.SystemName))
{
var themeRegistry = context.ActionContext.HttpContext.RequestServices.GetRequiredService<IThemeRegistry>();
var theme = themeRegistry.GetThemeDescriptor(themeName);
var combinedViewLocations = new[]
{
$"{theme.Path}Views/{{1}}/{{0}}" + RazorViewEngine.ViewExtension,
$"{theme.Path}Views/Shared/{{0}}" + RazorViewEngine.ViewExtension,
$"{module.Path}Views/{{1}}/{{0}}" + RazorViewEngine.ViewExtension,
$"{module.Path}Views/Shared/{{0}}" + RazorViewEngine.ViewExtension,
};
return combinedViewLocations.Union(viewLocations);
}
}
var moduleViewLocations = new[]
{
$"{module.Path}Views/{{1}}/{{0}}" + RazorViewEngine.ViewExtension,
$"{module.Path}Views/Shared/{{0}}" + RazorViewEngine.ViewExtension,
};
return moduleViewLocations.Union(viewLocations);
}
}
return viewLocations;
}
muratcakir
changed the title
Question about the order of view search paths
Resolve companion module and dependencies in ModuleViewLocationExpander
May 11, 2024
I made 2 Modules for our shop.
First one (MyCodeModule) is for Controllers, Domain, WebApi etc and the second one is for solely Theming (Theme WBlue).
What I now encountered (after having a typo) is this:
My Question:
Shouldn't the MyCodeModule paths be checked after the themes?
Because at the moment I can not theme a controller/cshtml defined in
MyCodeModule
in my WBlue theme. Although the_custom.css
of the theme is used.It doesn't pose a problem for me since both modules are under my control but in other constellations one might want to be able to theme a view of another module.
Btw, I did set Order and DepdendsOn in the module.json properly so the theme depends on the code module. But the code in the
IViewLocationExpander
s doesn't account for any dependency sorting.The text was updated successfully, but these errors were encountered: