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

Forums / General Discussions / CSS / Theme Selector

CSS / Theme Selector

11 posts, 1 answered
  1. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    31 Aug 2010
    Link to this post
    How would I go about creating a control for users changing the theme of a site on the frontend, similar to the theme button when editing a page?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Sep 2010
    Link to this post
    Hello Kristian,

    Here is a sample code that illustrates how to change the Theme at runtime

    var manager = PageManager.GetManager();
    SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
    Guid pageId = ((PageSiteNode)currentNode).PageId;
    var draft = manager.EditPage(pageId, true);
    draft.Theme = "test2";
    manager.PublishPageDraft(draft.Id, true);
    manager.SaveChanges();
    SiteMapBase.Cache.Flush();
    Response.Redirect(currentNode.Url);


    Best wishes,
    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. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    01 Sep 2010
    Link to this post
    Thank you,

    would there be a way to propagate this change to all pages? or at least apply this to the template so all pages using that template would reflect the new theme?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Sep 2010
    Link to this post
    Hello Kristian,

    Here is a sample code that illustrates how to change the template theme, but there are issues with setting this at runtime and you have to edit the page and then save it.

    var manager = PageManager.GetManager();
     var templateID = manager.GetTemplates().Where(t => t.Title == "Copy of Default").SingleOrDefault().Id;
     var editTemplate = manager.EditTemplate(templateID, true);
     editTemplate.Theme = "test2";
     manager.SaveTemplateDraft(editTemplate.Id);
     manager.PublishTemplateDraft(editTemplate.Id);
     manager.SaveChanges();
     SiteMapBase.Cache.Flush();

    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
  5. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    01 Sep 2010
    Link to this post
    I'm not sure if I have this working correctly. I set both my template and page to use no theme on the backend. Then I click on the button on my page to change the template theme. I check the template under page templates and i see the new theme is reflected in the editor. I click publish on the theme and then refresh the page i wanted the theme to change. but it still appears as no theme.

    Will this be resolved after the beta? Would this be the best way of changing the overall theme of the site?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Sep 2010
    Link to this post
    Hi Kristian,

    Editing the page should apply the theme on it properly. As I wrote there are issues with this process when you are working programatically and we have logged this issue for fixing.

    Greetings,
    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
  7. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    24 Nov 2010
    Link to this post
    finally got back around to this but receive a 403 when trying to retrieve the css
    GET main.css
    http://localhost:26688/TestSite/App_Data/Sitefinity/WebSiteTemplates/UserDefined/App_Themes/Red/Global/main.css
    403 Forbidden
    localhost:26688
    1.2 KB

    HtmlLink link = new HtmlLink();
            link.Href =
                "~/App_Data/Sitefinity/WebSiteTemplates/UserDefined/App_Themes/Red/Global/main.css";
            link.Attributes.Add(HtmlTextWriterAttribute.Rel.ToString(), "stylesheet");
            Page.Header.Controls.Add(link);

  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Nov 2010
    Link to this post
    Hello Kristian,

    It looks like you have the same problem as this one discussed here.

    Sincerely yours,
    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
    Answered
  9. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    24 Nov 2010
    Link to this post
    Thanks for the help, i solved it by just starting the path from ~/Sitefinity instead of ~/App_Data
  10. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    24 Nov 2010
    Link to this post
    How come certain widgets do not work the same with a custom theme, for example the lightbox option for an image gallery?
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Nov 2010
    Link to this post
    Hello Kristian,

    You have something in your theme/template that breaks the widget. Is there any information in the browser console - js error, css loading issues etc.

    Kind 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
11 posts, 1 answered