ADMIN Theme?

Topics: Developer Forum, User Forum
Oct 15, 2008 at 5:06 PM
Hello,

I am interested in having a different theme used when the ADMIN is logged in. But only the admin, not POWER Users or other roles. Can anyone help with this please?

Thanks ahead of time,
TJ Havens
Oct 16, 2008 at 1:47 AM
Edited Oct 16, 2008 at 1:54 AM
Hey xotj123,
                    Add these lines to your App_Code/Contols/PageBaseClass.cs file. Replace TravelDiary with your theme of chice.
line________code____________________________

 

 

50    if (User.IsInRole("Administrators"))


51   Theme = (
"TravelDiary");


52   
else


53   Theme = _website.Theme;


THEFAV

 

 

 

 

 

 

 

 

Oct 16, 2008 at 3:32 PM
FAV,

Here is my code, can you please show me where to put it.

Thanks,
TJ Havens

//===============================================================================================
//
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.
//
//===============================================================================================

using System;
using System.Web.UI;
using System.IO;
using System.Threading;
using System.Globalization;
using System.Web.UI.HtmlControls;

namespace MyWebPagesStarterKit.Controls
{
    public abstract class PageBaseClass : Page
    {
        protected WebSite _website;

        public PageBaseClass(){}

        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);
            _website = WebSite.GetInstance();

            //MWPSKex.#004
            string themeToApply = string.Empty;
            WebPage page = string.IsNullOrEmpty(Request.QueryString["pg"]) ? new WebPage(_website.HomepageId) : new WebPage(Request.QueryString["pg"]);
            themeToApply = page.CustomPageTheme;
            if (string.IsNullOrEmpty(themeToApply))
            {
                // fallback: inherit theme from website settings if no theme has been set at page level
                themeToApply = _website.Theme;
            }

            if((themeToApply == string.Empty) || (!Directory.Exists(Server.MapPath(string.Format("~/App_Themes/{0}", themeToApply))))){
                string appThemesPath = Server.MapPath("~/App_Themes");
                string[] themes = Directory.GetDirectories(appThemesPath);
                if (themes.Length > 0)
                {
                    //if theme TravelDiary, select as default, else choose first theme
                    bool blnTravelDiary = false;
                    foreach (string theme in themes)
                    {
                        if (Path.GetFileName(theme) == "TravelDiary")
                            blnTravelDiary = true;
                    }
                    _website.Theme = blnTravelDiary == true ? "TravelDiary" : Path.GetFileName(themes[0]);
                }
                else
                {
                    _website.Theme = string.Empty;
                }
                themeToApply = _website.Theme;
                if (page != null)
                    page.CustomPageTheme = themeToApply;
                _website.SaveData();
            }
            Theme = themeToApply;
        }

        protected override void InitializeCulture()
        {
            // Initialize Resource Manager - with no effect if it's already been initialized
            string LocaleID = WebSite.GetInstance().LocaleID;
            UICulture = LocaleID;
            Culture = LocaleID;
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(LocaleID);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(LocaleID);
            base.InitializeCulture();
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (_website.Theme == "Arabic")
            {
                HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("body1");
                body.Attributes.Add("dir", "rtl");
            }
        }
    }
}

Oct 16, 2008 at 9:50 PM
Hello,

Thanks for the quick reply THEFAV!

One other issue, I would also like to hide the ADMIN_Theme from selection in the Admin as a THEME Selection, is this possible?

Thanks,
Oct 24, 2008 at 6:03 PM
I don't think this is a good approch. You have to adapt a whole new theme to achieve the same goal as creating a new masterpage with a different Template.
In my solution I have masterpage that is default for all adminpages without any change to a theme. You can then set a template by adding a path to admin masterpage in website settings.
The PageBase class selects the PageTheme for each page that is requested.

But if you like to duplicate a whole theme I this is ok.