Thanks you for your solution, skyler.severns
ScottMc101 wrote:Does anyone know the best way to generate the dynamic path for themed images in NopCommerce 2.0 ??
I currently have the following code as part of a plugin, however I would like for the images to be themable based on the current site theme, which would mean that it would search for the images in the /themes/ folder.
I found another post but it was for the NopCommerce 1.x versions and doesn't seem to apply to MVC razor.
Any help would be appreciated!
Current cshtml code:
<img src="@Url.Content("~/ ?? THEME PATH ?? /Content/images/ico-facebook.png")" alt="" />
I updated as following and it worked.
My project was using current theme named CustomTheme.I put this in file EditorExtensions.cs (located in Presentation\Nop.Web\Extensions)
public static string CurrentThemePath(this UrlHelper u, string url)
{
var ctx = EngineContext.Current.Resolve<IThemeContext>();
url = string.Format(url, ctx.WorkingTheme);
return UrlHelper.GenerateContentUrl(url, HttpContext.Current.Request.RequestContext.HttpContext);
}
On view, I call it as following example:
<img src='@Url.CurrentThemePath("~/Themes/{0}/Content/Images/logo.png")' alt="@T("Common.Logo")" width="150" height="170" />
That will be renderred as:
<img width="150" height="170" alt="logo" src="/[myProjectName]/Themes/CustomTheme/Content/Images/logo.png" />
Wish this post help some others.