Theming Partial Views (non-standard locations)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Is there already a method for theming partial views stored in non-standard locations (e.g. “~/Views/{not-current-controller}/PartialView.cshtml”). Partial views stored within one controller section, but used by a different controller are not overridden by the theme.

I was wondering if there is already a method for enabling this or if it will require custom code to support this functionality.

Just to be clear theming partial views works when referenced like @Html.Partial(“PartialView.cshtml”), but theming partial views fail when the view exists under another controller. You can reproduce this issue by overriding “Catalog\_SearchBox.cshtml” in a theme. Below is the code used to reference the search box view from Header.cshtml.


@Html.Partial(“~/Views/Catalog/_SearchBox.cshtml”)
12 years ago
I don't know how to fix it (haven't looked yet). But the issue is in ThemeableVirtualPathProviderViewEngine class. GetPathFromSpecificName() method just doesn't search in \Themes\.
12 years ago
a.m. wrote:
I don't know how to fix it (haven't looked yet). But the issue is in ThemeableVirtualPathProviderViewEngine class. GetPathFromSpecificName() method just doesn't search in \Themes\.


Thanks for the response Andrei. I'll look into it further tomorrow and let you know if I can get something working.
12 years ago
Hi Skyler,

we had the same problem. The way we implemented it is to override the main(not partial) views in the theme and from them to call the partial views by their full path in the theme.

In other words for the given scenario we override the main _Root.cshtml view and from there we call the Header.cshtml partial view by @Html.Partial("Header.cshtml") - the Header view will be correctly overridden if it is in the same controller/folder, where the view from which it is called is present. In this case the _Root and Header views are both in the Shared folder of the views in the theme, so everything is correct.  And finally from the Header view we explicitly call @Html.Partial("~/Themes/{ThemeName}/Views/Catalog/_SearchBox.cshtml"). Thus we override the "~/Views/Catalog/_SearchBox.cshtml" view.

We think it is not the best possible solution, because in order to override some of the partial views you will need to override the main views.

The best way would be if the ViewEngine searches by path like "Views/Catalog/_SearchBox" not only in the root folder, but also in the folders for each theme.

Hope this helps!
12 years ago
7Spikes wrote:
Hi Skyler,

we had the same problem. The way we implemented it is to override the main(not partial) views in the theme and from them to call the partial views by their full path in the theme.

In other words for the given scenario we override the main _Root.cshtml view and from there we call the Header.cshtml partial view by @Html.Partial("Header.cshtml") - the Header view will be correctly overridden if it is in the same controller/folder, where the view from which it is called is present. In this case the _Root and Header views are both in the Shared folder of the views in the theme, so everything is correct.  And finally from the Header view we explicitly call @Html.Partial("~/Themes/{ThemeName}/Views/Catalog/_SearchBox.cshtml"). Thus we override the "~/Views/Catalog/_SearchBox.cshtml" view.

We think it is not the best possible solution, because in order to override some of the partial views you will need to override the main views.

The best way would be if the ViewEngine searches by path like "Views/Catalog/_SearchBox" not only in the root folder, but also in the folders for each theme.

Hope this helps!


Thanks for the response 7Spikes. That is how we've done it for now, but like you said it probably isn't the best solution. I'll try and dig into the code and see if I can find an appropriate way to modify the view engine to allow for this functionality.
12 years ago
hi skyler,

do we have an update on this? i seem to have hit the same issue., using nop 2.4 and i cant even get to do it the way described here, ill work more on it for now i guess, i cant override anything...
12 years ago
hacknop wrote:
do we have an update on this?

This issue was fixed in version 2.30
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.