Ciwan wrote:Are there any limitations or undesired side effects to the above code ?
I'm just curious .. cause if only a few lines of code allows such good functionality, why didn't the development team behind nopCommerce use it !
No one from Nop Team answered. Will this change be made for 2.20? (please :)
The solution worked for me (thanks asoares), but it was a bit painful going through 3 pages of this thread and the issues encountered, so here's the summary...
To create a custom Theme that includes Views, these modifications are needed to get all custom Views processed thru view engine (including those used as Layout - e.g. _Root.cshtml, _ColumnsThree.cshtml, etc.)
1) Modify file
\src\Presentation\Nop.Web.Framework\ViewEngines\Razor\WebViewPage.cs
before line
public abstract class WebViewPage : WebViewPage<dynamic>
paste this code
public abstract class ExtendedWebViewPage<TModel> : Nop.Web.Framework.ViewEngines.Razor.WebViewPage<TModel>
{
public override string Layout
{
get
{
var layout = base.Layout;
if (!string.IsNullOrEmpty(layout))
{
var filename = System.IO.Path.GetFileNameWithoutExtension(layout);
ViewEngineResult viewResult = System.Web.Mvc.ViewEngines.Engines.FindView(ViewContext.Controller.ControllerContext, filename, "");
if (viewResult.View != null)
{
layout = (viewResult.View as RazorView).ViewPath;
}
}
return layout;
}
set
{
base.Layout = value;
}
}
}
public abstract class ExtendedWebViewPage : ExtendedWebViewPage<dynamic>
{
}
2) Create a Theme subfolder, and copy needed subfolders/css/Views/etc.
(just copy the files you actually modify to make sure to use the latest version of the views you don't)
\src\Presentation\Nop.Web\Themes\<your theme folder>
3) In web.config files - both
\src\Presentation\Nop.Web\Views\Web.config
\src\Presentation\Nop.Web\Themes\<your theme folder>\Views\Web.config
replace
<pages pageBaseType="Nop.Web.Framework.ViewEngines.Razor.WebViewPage"> -->
with
<pages pageBaseType="Nop.Web.Framework.ViewEngines.Razor.ExtendedWebViewPage">
4) Build App