Current Theme Name within view?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
Is there capability to get the current theme name within a view?

The current theme name is needed for plugins that have custom JS and CSS files which need added (example below):

@Html.AddScriptParts("~/Themes/" + CurrentThemeName + "/Content/custom.js");


Or, perhaps there is an alternative/better approach?
10 years ago
breakskater wrote:
Is there capability to get the current theme name within a view?

The current theme name is needed for plugins that have custom JS and CSS files which need added (example below):

@Html.AddScriptParts("~/Themes/" + CurrentThemeName + "/Content/custom.js");


Or, perhaps there is an alternative/better approach?


ThemeContext should do the trick. :D
10 years ago
why not load the files from your plugin content folder?
I will not be loaded twice, if the file exists on another page.
4 years ago
breakskater wrote:
Is there capability to get the current theme name within a view?

The current theme name is needed for plugins that have custom JS and CSS files which need added (example below):

@Html.AddScriptParts("~/Themes/" + CurrentThemeName + "/Content/custom.js");


Or, perhaps there is an alternative/better approach?



@inject Nop.Web.Framework.Themes.IThemeContext themeContext
@{
    var themeName = themeContext.WorkingThemeName;
    Layout = $"~/Themes/{themeName}/Views/Shared/_ColumnsOne.cshtml";
}
2 years ago
Arash is right. But in my case, I'm using it like this:

@using Nop.Core.Infrastructure
@using Nop.Web.Framework.Themes

@{
var themeName = EngineContext.Current.Resolve<IThemeContext>().WorkingThemeName;
}

@Html.AddScriptParts(string.Format("~/Themes/{0}/Content/custom.js", themeName));
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.