4.40 Override View in Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 anni tempo fa
I'm trying to change what is displayed in the No Results section on the _ProductsInGridOrLines.cchtml view by having a custom plugin.

I can't seem to find any good documentation around how to accomplish this and looks like the RouteProvider class is now different in 4.40.

Thanks!
2 anni tempo fa
There are probably other ways but if you want to load your version of _ProductsInGridOrLines.cshtml from a plugin folder you can use a CustomViewEngine

See some code here https://www.nopcommerce.com/en/boards/topic/85129/how-to-make-custom-view-engine-in-nopcommerce-43
Also see https://www.nopcommerce.com/en/boards/topic/91885/viewlocationexpander-cannot-find-views-in-plugin-if-same-view-exists-in-theme-or-default-view-in-nop
2 anni tempo fa
Hey Yidna,

I was able to get this to work, there was an issue with another plugin that we were using that had a different controller so I had to add the direct controller folder to the view locations.

Code

ViewLocationExpander : IViewLocationExpander
{
  public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
  {
            // Have to manually include the Catalog because the 7Spikes plugins have a Catalog7Spikes controller,
            //  so that will default to the base view
            IEnumerable<string> expandedLocations = new string[]
            {
                "~/Plugins/<PluginName>/Views/{1}/{0}.cshtml",
                "~/Plugins/<PluginName/Views/Catalog/{0}.cshtml"
            };        

            viewLocations = expandedLocations .Concat(viewLocations);
            return viewLocations;
  }

   public void PopulateValues(ViewLocationExpanderContext context)
    {
            // No values needed to populate
    }
}

public class DependencyRegistrar : IDependencyRegistrar
{
   public void Register(IServiceCollection services, ITypeFinder typeFinder, AppSettings appSettings)
        {  
    services.Configure<RazorViewEngineOptions>(o =>{
                o.ViewLocationExpanders.Add(new ViewLocationExpander());
            });
  }
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.