Hiding RibbonRow in SharePoint 2010 portal sites

As shown in one of my earlier posts on SharePoint 2007 we have a need to hide our RibbonRow & Login data from some of our websites to make it more pleasing for people to look at.

Doing this is slightly more tricky in 2010 then it was in 2007; 2010 allows less code to be put directly into the master pages i.e. it’s more strict about it. Our previously posted fix to this no longer works. After some fiddling around I have found a rahter novel way of solving the issue.

First I wrapped the Ribbonbar in a DIV that would move it to another position. This is easely done. Just find the beginning of the ribbon:

<div id=”s4-ribbonrow” >

Next part get’s a little bit tricky to follow, in order to allow us to actually run script code we need to run it server side. So we wrap our DIV in another DIV and give this DIV the runat=”server” tag.

<div runat=”server”>
<div id=”RibbonWrap”>
<div id=”s4-ribbonrow” >
</div>
</div>

Now in order to show or hide our ribbon we used the same basic script as before; We show the ribbon if the URL includes the ?login=login value or if users are already logged in.

<div runat=”server”>
<%
SPUser currentUser = SPContext.Current.Web.CurrentUser;
string DisplayLogin = Request[“login”];
if ((currentUser != null) || (DisplayLogin != null)) {
Response.Write(“<div id=’RibbonWrap’>”);
} else {
Response.Write(“<div id=’RibbonWrap’ style=’display:none’>”);
}
%>
<div id=”s4-ribbonrow” >
</div>
</div>

Here you can we added the previously used script. Minor change in the way SharePoint 2010 and 2007 ommit the currently logged in user but other then that the script is essentially the same. Where it deviates is because we can no longer wrap the entire RibbonRow between { } tags. SharePoint 2010 won’t allow this, so instead we opted to Response.Write the DIV with or without a display:none style tag.

Leave a Reply

Your email address will not be published. Required fields are marked *