Using ExpandViewLocations in a plugin to search for more view locations in a plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hello.

I am trying to add a new category template, which should be found in my plugin.

I guess i could just add the full path to the category template path, but i would like to use the ExpandViewLocation to achive this instead.

When i navigate to a category with the selected template, it searches through many locations(theme, different nop-templates plugins etc), but not the location of my plugin.

I have the following code:

public class ViewLocationExpander : IViewLocationExpander
    {
        public void PopulateValues(ViewLocationExpanderContext context)
        {
        }

        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {
          
                viewLocations = new string[] { $"/Plugins/CUSTOM.MyPlugin/Views/{{0}}.cshtml",
                                          $"/Plugins/CUSTOM.MyPlugin/Views/Shared/{{0}}.cshtml"}.Concat(viewLocations);


            return viewLocations;
        }
    }
4 years ago
The string in my CustomViewEngine has the ~
viewLocations = new[] {$"~/Plugins/Group.Name/Views/Shared/Components/CustomCustomerNavigation/Default.cshtml"}
.Concat(viewLocations);

Also are you loading it the startup ?
services.Configure<RazorViewEngineOptions>(o =>
{
     o.ViewLocationExpanders.Add(new CustomViewEngine());
});
4 years ago
Yidna wrote:
The string in my CustomViewEngine has the ~
viewLocations = new[] {$"~/Plugins/Group.Name/Views/Shared/Components/CustomCustomerNavigation/Default.cshtml"}
.Concat(viewLocations);

Also are you loading it the startup ?
services.Configure<RazorViewEngineOptions>(o =>
{
     o.ViewLocationExpanders.Add(new CustomViewEngine());
});



I think i forgot about registering in startup. Ill check later. Thanks!
4 years ago
Yeah. Its working now. Thanks.

Although, overriding the nop-template ajax filter view wasnt that easy. The name of the new category view has to be the same for nop and nop-template ajax filter, and nop got confused when loading the views. The nop-template ajax view got loaded when it should have used the other one etc.

I gotta find a solution for this in the future.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.