how can I reference "current theme" image from master page
I need to reference a theme-specific image in my master page.
The image lives in ~/App_Data/Sitefinity/WebsiteTemplates/MyTemplate/App_Themes/MyTheme/Images/
It works if I reference it like this from the master page:
<img src="/Sitefinity/WebsiteTemplates/MyTemplate/App_Themes/MyTheme/Images/image.png" />
But that hard-codes the theme name and path, whereas I need to be able to dynamically switch which theme is applied to the template via the admin settings.
Isn't there a way to reference the source of the image so that it changes when the theme changes?
FWIW, this master page lives at ~/App_Data/Sitefinity/WebsiteTemplates/MyTemplate/App_Master/MyTemplate.master
Thanks,
Kevin
Did you ever get a response or figure this one out? I want to do the same thing from a custom user control.
Jason,
Here's some code to get the name of the current theme, which you can use in image source path.
public static class Utility
public static string GetCurrentTheme()
Guid currentPageId = GetCurrentPageId();
PageNode pn = GetPageNode(currentPageId);
return GetPageTheme(pn);
public static Guid GetCurrentPageId()
Guid pageId;
PageSiteNode psn = SiteMapBase.GetActualCurrentNode();
if (psn == null)
PagesConfig pagesConfig = Config.Get<
PagesConfig
>();
pageId = pagesConfig.HomePageId;
else
pageId = psn.Id;
return pageId;
public static PageNode GetPageNode(Guid pageId)
var pf = App.WorkWith().Page(pageId);
return pf.Get();
public static string GetPageTheme(PageNode pn)
return (pn.Page.Template != null) ? pn.Page.Template.Theme : "";