nopCommerce - Dynamic theme activation for different pages - Not multi store

276 views Asked by At

I was wondering how we can activate different themes on different pages dynamically. For example few pages will have theme-1 and rest of the site will have theme-2. Users will not be selecting the themes. It will have to be set dynamically from the back end.

One way is to have separate master pages.

But is it possible that we have two nopCommerce themes and we activate any one dynamically on different pages of the same store? Not multi store.

1

There are 1 answers

1
Marco Regueira On BEST ANSWER

It should be possible following these steps:

  1. Create a new plugin.
  2. Copy the current class ThemeContext, implementing IThemeContext to your plugin. Use a different name to avoid mistakes (see).
  3. Register the new class with Autofac. Set a higher priority to ensure that the new class replaces the old ThemeContext. Enable the plugin and check it works by setting a breakpoint there.
  4. Change the get part of the property WorkingThemeName in your new class and implement any business rules you need, returning the alternate theme name when appropriate. You may need to access the current RouteData to get the current route controller or parameters for each http request.

That's all. It is easier than it looks.