CSS

Provisionate MasterPage and CSS with Feature

Posted on Updated on

Sometimes, when you don’t want to use Powershell, you can set your branding from a Feature, it’s the old procedure but very “elastic”.

In the bellow sample, I’ll give you the option to change you master page to Front Office and Back Office, you can also define your CSS File.

I’m processing all Sub Webs also, just change what you want. This is a Feature SCOPE Site

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    using (var site = properties.Feature.Parent as SPSite)
    {
        if (site == null) return;
        using (var web = site.OpenWeb())
        { 
            var masterUrl = web.Site.ServerRelativeUrl == "/" ? 
                "/_catalogs/masterpage/YOURCustomFO.master" : web.Site.ServerRelativeUrl + 
                                                            "/_catalogs/masterpage/YOURCustomFO.master";
            var customMasterUrl = web.Site.ServerRelativeUrl == "/" ? 
                "/_catalogs/masterpage/seattle.master" : web.Site.ServerRelativeUrl + 
                                                         "/_catalogs/masterpage/seattle.master";
            //string cssUrl = web.Site.ServerRelativeUrl == "/" ? "/Style Library/xx.css" : web.Site.ServerRelativeUrl + "/Style Library/xx.css";

            #region MasterPage e CSS

            // Define Master page for FO and BO
            web.CustomMasterUrl = masterUrl;
            web.MasterUrl = customMasterUrl;

            //Alternate CSS URL 
            //web.AlternateCssUrl = cssUrl;

            // inheritance settings
            web.AllProperties["__InheritsMasterUrl"] = "True";
            web.AllProperties["__InheritsCustomMasterUrl"] = "True";
            //web.AllProperties["__InheritsAlternateCssUrl"] = "True";

            web.Update();

            foreach (SPWeb subWeb in web.Webs)
            {
                try
                {
                    ProcessSubWebs(subWeb);
                }
                finally 
                {
                    if (subWeb != null)
                        subWeb.Dispose();
                }
            }
            #endregion
        }
    }
} 
Advertisements

Some things you want to hide in your Master Page

Posted on Updated on

<style>            
	/* Turns off the border on the bottom of the tabs */
	.ms-cui-ribbonTopBars > div {
		border-bottom: 1px solid transparent !important;
	} 
	/* Hide Ribbon */
	#s4-ribbonrow {
		display: none;
	}

	/* Hide Suite Bar */
	#suiteBar {
		display: none;
	}

	/* Remove Left Navigation Bar */
	#sideNavBox {
		DISPLAY: none;
	}

	/* Remove Logo */
	#s4-titlerow {
		display: none !important;
	}
</style> 

Hide Ribbon and Suite Bar from Anonymous Users

Posted on Updated on

SharePoint 2013, like 2010 have Trimmed Controls in order to define display rules for Authentications Roles. In SharePoint 2013 we have the Suite Bar, you must hide it also as Trimmed like this

Find the <body in Master Page and add the <style>

<body>
    <style>
        #s4-ribbonrow {
            display: none;
        }
    </style>
    <style>
        #suiteBar {
            display: none;
        }
    </style>
 
Add the Trimmed Control for before <div id=”s4-titlerow” for permissions PermissionsString=”AddAndCustomizePages”
 

<SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControlRibbon" runat="server" PermissionsString="AddAndCustomizePages">
    <script type="text/javascript">
        document.getElementById("s4-ribbonrow").style.display = "block";
        document.getElementById("suiteBar").style.display = "block";
    </script>
</SharePoint:SPSecurityTrimmedControl>