More in this section

Forums / Developing with Sitefinity / Page theme based on category

Page theme based on category

2 posts, 0 answered
  1. Anthony Smith
    Anthony Smith avatar
    34 posts
    Registered:
    08 Dec 2009
    13 Feb 2010
    Link to this post
    Hi,

    I'm looking to create a way of defining the page theme based on the category, for example:

    Category 1 = Red Background Theme
    Category 2 = Blue Background Theme

    Has anyone implemented something similar to this?

    Thanks,

    Anthony
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Feb 2010
    Link to this post
    Hello Anthony Smith,

    You need to create a custom class that inherits from InternalPage. Then you can override GetMasterPageName  and GetTheme to set your custom theme based on the category name

    sample code

    using System;
    using Telerik.Cms;
    using Telerik.Cms.Web;
      
    namespace Telerik.Sitefinity.Samples
    {
        public class CustomInternalPage : InternalPage
        {
            protected override void OnPreInit(EventArgs e)
            {
                if (!String.IsNullOrEmpty(this.Request.QueryString["templ"]))
                {
                    string getTemplateName = this.Request.QueryString["template"];
                    this.currentTheme= this.Manager.GetTemplate(getTemplateName );
                }
      
                base.OnPreInit(e);
            }
      
            protected override string GetMasterPageName(Telerik.Cms.IPageContent pageContent)
            {
              
                return base.GetMasterPageName(pageContent);
            }
      
            protected override string GetTheme(IPageContent pageContent)
            {
                if (this.currentTheme!= null)
                {
                    if (pageContent != null && String.IsNullOrEmpty(pageContent.Theme))
                        return currentTheme.Theme;
                }
                return base.GetTheme(pageContent);
            }
        }
    }
     
            private IPageTemplate currentTheme = null;

    Finally set CustomInternalPage in cmsentrypoint.aspx

    <%@ Page Inherits="Telerik.Sitefinity.Samples.CustomInternalPage" MasterPageFile="~/Sitefinity/Dummy.master" %>


    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.
2 posts, 0 answered