how can I reference "current theme" image from mas

Posted by Community Admin on 03-Aug-2018 19:59

how can I reference "current theme" image from master page

All Replies

Posted by Community Admin on 27-Jan-2011 00:00

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

Posted by Community Admin on 27-Mar-2011 00:00

Did you ever get a response or figure this one out?  I want to do the same thing from a custom user control.

Posted by Community Admin on 28-Mar-2011 00:00

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 : "";
        
  

This thread is closed