Mvc + Theme support

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

I encountered a problem while creating a theme for the upcoming asp.net mvc version of nopCommerce and wanted to discuss it. I noticed that the custom view engine allows to "override" views such that views with the same name will be found first in the current theme's folder. However, to use that feature with a master page, one must specify the name of the master page in a controller action's return statement (since hardcoding the path to the master view on the Layout attribute of the view does not process through the view engine).

However, I think this method doesn't work with nested layouts (for instance, I can specify


return View("Index", "_ColumnsThree");


in the HomeController to have the Index view load my custom _ColumnsThree master page. But _ColumnsThree will still load the default _Root view, unless I change the path in my custom _ColumnsThree to be relative to load my custom _Root. This would work until I just want to override _Root. Since _Root is never used as a direct master, I can't go and change the code in the controllers (as shown above).

One solution I came up with to make sure the themed version of a view is always used is to force the layout to go through the view engine to locate a view:


Layout = (ViewEngines.Engines.FindView(this.ViewContext.Controller.ControllerContext, "_ColumnsThree", "").View as RazorView).ViewPath;


This is the code I use in Index.cshtml. This code should be abstracted away in a helper and used on all Layout statements instead of hardcoding the paths to the master views. This way, someone can create a theme, override any view and be sure that it will be used.

Please let me know if it can be useful or if I overlooked something.
Thanks!
12 years ago
where is option to change theme in administration?
12 years ago
pepper, you mean in 1.9 right ??


admin  configuration --> global settings    SEO/Display  tab      look for    store theme :
12 years ago
in 2.0 mvc nop codeplex
12 years ago
pepper wrote:
where is option to change theme in administration?


no rush v2.00 is still NOT in RC or even BETA version codeplex is only for preview to track development. No reason to make some styles or anything because code, markup or css developers can "and will" change at any time until full version is released.

Take it easy! everyone waiting for v2.00
12 years ago
according to this beta versn will be avalb soon by end of june https://www.nopcommerce.com/boards/t/10206/is-nopcommerce-20-going-to-have-all-the-features-that-19-has.aspx

which means only 10 to 15 days to go.

Still need help with option to change theme in 2.0mvc codeplx version.
12 years ago
pepper wrote:
according to this beta versn will be avalb soon by end of june https://www.nopcommerce.com/boards/t/10206/is-nopcommerce-20-going-to-have-all-the-features-that-19-has.aspx

which means only 10 to 15 days to go.

Still need help with option to change theme in 2.0mvc codeplx version.


So we still have a time. if you track cedeplex project you will find that yesterday theme selector has been added to administration panel. check codeplex every day and you will be up to date.
12 years ago
thanks for info.

i will download new version asap from codeplex.
12 years ago
Temporarily going forward with my idea of allowing a user to create a theme that can also override master pages set using the Layout property while currently trying to avoid changing the @Layout statement of all views, here's what I did in case someone wants to do it.

I created a new class derived from Nop.Web.Framework.ViewEngines.Razor.WebViewPage. I changed the reference to Nop.Web.Framework.ViewEngines.Razor.WebViewPage in the web.config file to point to my new class so that all views now use my class as the base view. In my class, I've overridden the Layout property such that when a value is set, I get the filename without the extension, I process it through the ThemableViewEngine and set the found view's ViewPath back to base.Layout.

Please keep in mind that this is a work in progress. If someone has a better idea to accomplish that, please let me know!

Thanks!
12 years ago
I would love to see the modified code for this.. Would you mind sharing your code just to see and learn from it?

If that is possible of course, could you send me a PM
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.