+1-888-365-2779
Try Now
More in this section

Forums / Designing with Sitefinity / GenericContent and Themeing

GenericContent and Themeing

8 posts, 0 answered
  1. Byzza
    Byzza avatar
    89 posts
    Registered:
    09 Jul 2007
    12 Mar 2010
    Link to this post
    Ok, I know the Rad Editor doesn't inherit the theme and there are heaps of posts on how too add a reference to the EditorToolsFile.xml to point to a css file, but unfortunatly my project uses 2 completely different Theme's depending on the page, and I can't just hard code a reference to a CSS file.  I need the genericContent Editor to pick up the Theme of the page and apply it. 

    I'm happy to do some Coding if needed, though I'd need some step by step help.

    Thank you in advance.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Mar 2010
    Link to this post
    Hi Byzza,

    You can add the css files reference at runtime. For more detailed information you could take a look at




    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Byzza
    Byzza avatar
    89 posts
    Registered:
    09 Jul 2007
    12 Mar 2010
    Link to this post
    Hi, thanks for that.  but is there an API or something that will return the theme of the page. that way I can grab the css files from the theme directory and reference them.

    Thank you in advance for you help
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Mar 2010
    Link to this post
    Hi Byzza,

    You can add the following code OnPreRender. It will return the current page theme

    CmsManager cmsMgr = new CmsManager();
    ICmsUrlContext pageKey = (ICmsUrlContext)this.Context.Items[Telerik.Cms.Web.UrlHelper.CmsPageKey];
    Guid currentPageID = pageKey.PageID;
    ICmsPage page = (ICmsPage)cmsMgr.GetPage(currentPageID);
    var theme = page.Theme;


    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Byzza
    Byzza avatar
    89 posts
    Registered:
    09 Jul 2007
    15 Mar 2010
    Link to this post
    mmm, ok, well I've added in the external template for the GenericContent

    and now added in this code to the file (<project>/Sitefinity/Admin/ControlTempaltes/Generic_Content/GenericContentDesigner.ascx):
    protected void Page_PreRender(object sender, EventArgs e)
       {
           Telerik.Cms.CmsManager cmsMgr = new Telerik.Cms.CmsManager();
           Telerik.Cms.Web.ICmsUrlContext pageKey = (Telerik.Cms.Web.ICmsUrlContext)this.Context.Items[Telerik.Cms.Web.UrlHelper.CmsPageKey];
           Guid currentPageID = pageKey.PageID;
           Telerik.Cms.ICmsPage page = (Telerik.Cms.ICmsPage)cmsMgr.GetPage(currentPageID);
           var theme = page.Theme;
           if (theme == "StyleGuide")
           {
               Response.Write("bob");
               textEditor.CssFiles.Add("~/App_Theme/Bradken/styleSheet.css");
               textEditor.CssFiles.Add("~/App_Theme/Bradken/additions.css");       
           }
           else
           {
               Response.Write("ted");
               textEditor.CssFiles.Add("~/App_Theme/Bradken/bradken.css");
           }
       }

    but I'm getting the error:
    System.NullReferenceException: Object reference not set to an instance of an object
    on line 17:
    Line 15:         Telerik.Cms.CmsManager cmsMgr = new Telerik.Cms.CmsManager();
    Line 16:         Telerik.Cms.Web.ICmsUrlContext pageKey = (Telerik.Cms.Web.ICmsUrlContext)this.Context.Items[Telerik.Cms.Web.UrlHelper.CmsPageKey];
    Line 17:         Guid currentPageID = pageKey.PageID;
    Line 18:         Telerik.Cms.ICmsPage page = (Telerik.Cms.ICmsPage)cmsMgr.GetPage(currentPageID);
    Line 19:         var theme = page.Theme;


    any help would be appreciated.

    Thank you
  6. Byzza
    Byzza avatar
    89 posts
    Registered:
    09 Jul 2007
    15 Mar 2010
    Link to this post
    I found a work around to the the pagekey being null, and that was to egnore the previous 2 lines just just use:

    Guid currentPageID = new Guid(Request.QueryString["sfpageid"]);

    So then this returns the correct page:

    Telerik.Cms.ICmsPage page = (Telerik.Cms.ICmsPage)cmsMgr.GetPage(currentPageID);

    but theme isn't returning anything.

    var theme = page.Theme;

    Looking at the page object there isn't even a Theme attribute.

    Again, any help would be appreciated.
    Thank you
  7. Byzza
    Byzza avatar
    89 posts
    Registered:
    09 Jul 2007
    15 Mar 2010
    Link to this post
    ok, well by debugging has been on fire today :)

    the reason the theme was returning "" was because it was set too "".   I have it set in the master page Template, and I don't want to have to apply it to every page.  (I.e. each page is set too "[Template Theme]")

    So instead of getting the page theme what I actually need is the Template theme.  Is this possible?
  8. Byzza
    Byzza avatar
    89 posts
    Registered:
    09 Jul 2007
    15 Mar 2010
    Link to this post
    ok, well I finally got it working.

    Here is my final code if anyone is interested
    protected void Page_PreRender(object sender, EventArgs e)
        {
            Telerik.Cms.CmsManager cmsMgr = new Telerik.Cms.CmsManager();
            Guid currentPageID = new Guid(Request.QueryString["sfpageid"]);
            Telerik.Cms.ICmsPage page = (Telerik.Cms.ICmsPage)cmsMgr.GetPage(currentPageID);
            var theme = page.Theme; 
            //Check page theme First
            if (theme == "")
            {
                //Page Theme is empty so get template Theme
                theme = page.Template.Theme;
                 AddStyles(theme);
            } else {
                AddStyles(theme);
            }  
        }
              
        void AddStyles(string strTheme )
        {
            if (strTheme == "StyleGuide")
            {
                Response.Write("bob");
                textEditor.CssFiles.Add("~/App_Themes/StyleGuide/styleSheet.css");
                textEditor.CssFiles.Add("~/App_Themes/StyleGuide/additions.css");
            }
            else
            {
                Response.Write("ted");
                textEditor.CssFiles.Add("~/App_Themes/Bradken/bradken.css");
            }
        }

    Regards
    Byron
Register for webinar
8 posts, 0 answered