Ribbon missing from Publishing Pages


Today I was creating a web template but basing it on a Publishing site template. I used the BLANKINTERNETCONTAINER. When my site was created, I realized that the ribbon bar was missing. I thought maybe because I selected the BLANKINTERNETCONTAINER which is a starter site for an internet facing site. I thought maybe this was the reason why the ribbon bar was missing, because it was an intranet site and most users would be visitors and not be requiring the ribbon.

So I changed the Base Template to be using the CMSPUBLISHING template instead. Still the Ribbon Bar was missing. In case it was a problem with my Web Template I created an out the box publishing site, and I still had no Ribbon.

Apparently you can turn it on by click on the cog (Site Actions) and selecting Show Ribbon. Also note that the Edit link shows up too.

I have found out how SharePoint knows if the Ribbon bar needs to show for the user. It is all based on a Cookie.

To prove this open your publishing site in Chrome and open the developer toolbar (F12). Now click on the resource tab. Under Cookies click on your site.

In the picture above, you will see the name ConsoleVisible0b4b4030-2d96-4443-a578-1150dc145e40 and the value set to true. If you now hide the ribbon bar the value will now say false. Alternatively you could delete the Cookie from Chrome by right clicking on it and clicking Delete, and refresh the page.

I have also discovered that the Guid after the ConsoleVisible is the Site.ID guid.

Now to permanently leave the Ribbon bar on, there is an option in the Site Settings -> Look and Feel -> Navigation. This opens _layouts/15/AreaNavigationSettings.aspx. Right at the bottom of this page there is a section called “Show and Hide Ribbon” By click the Yes option and then clicking OK, when you get back to your page you will see that the ribbon bar is there. And you can no longer Hide and Show the ribbon bar. It is permanently there. Also it doesn’t matter what your cookie is set at, the ribbon bar will always display.

It appears if you check the root site web properties using powershell an entry is added called __DisplayShowHideRibbonActionId. If this is set to true the ribbon bar is hidden, and can be toggled by the user. If this is set to false the ribbon bar is showing, and the user doesn’t have the choice to show or hide.

So I have learnt that I can enable it or disable it via cookie, web property. But how do I ensure that I can activate it in a web template? Well I was hoping that there was a property in a navigation type feature in the onet.xml file I could add. Unfortunately not. So the only option I have left is to create a web feature and add this feature to my onet.xml file. This option should also work for SharePoint 365.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <PropertyBag ParentType="Web" RootWebOnly="True">
 <Property Name="__DisplayShowHideRibbonActionId" Value="false" Type="string" />
 </PropertyBag>
</Elements>

Another option would be a feature that adds a javascript file to the masterpage that checks if the rootweb properties contains __DisplayShowHideRibbonActionId and either add/update/leave it accordingly. Although this would have overhead for every user who hits the page.

Advertisements

Error with Ribbon Buttons and redeploying SharePoint 2013 Apps


While doing a SharePoint hosted app, I wanted to add a button to the ribbon in the host web, that when clicked it would take me to the App, and pass in some tokens. Creating buttons for the ribbon in Visual Studio 2012 is a lot nicer now. You just add a new item and select “Ribbon Custom Action” from the Add New Item dialog. This takes you through a wizard to create the button.

After you have created your wizard, you will get the Elements.xml file that you used to have to hand crank yourself in Visual Studio 2010 and SharePoint 2010.

You will have noticed in the XML I have changed the CommandAction from “~appWebUrl/Pages/Default.aspx?” to “~appWebUrl/Pages/Default.aspx?{StandardTokens}&amp;SelectedList={SelectedListId}&amp;SelectedItems={SelectedItemId}”. This is so when I click the button on the List in the host web, it will redirect to the app and pass in the List ID and any selected items ID from the list. Full list of string tokens can be found on MSDN http://msdn.microsoft.com/en-us/library/jj163816.aspx . I deployed my app, went to an Announcement list, selected 2 items, clicked the Demo Ribbon button, and it redirected me to the app, and I could see in my URL the ID for the List, and ID’s of the two selected items.

I retracted the app by stopping debugging in Visual Studio. Now I proved my button worked, I wanted to update the JavaScript in App.js to handle my List ID and Selected Item ID’s. I made some changes to the App.js and redeployed my App again. I navigated to the Announcement list again, selected some items and click the button again. But then…

The JavaScript wasn’t even being hit, so what was going on? It wasn’t until I changed the CommandAction in the button’s element.xml back to the default ~appWebUrl/Pages/Default.aspx?{StandardTokens}, run the app again, and got the exact same message that made me realise that the button is cached in the browser. When you first deploy it to SharePoint, the ~appWebUrl is converted to the actual App Web URL. The next time you redeploy your app, the URL is a different address, but the details about the button are cached pointing to the old URL. Annoyingly the only way to fix, is to clear the cache in IE before each deployment.

  • Go to Internet Options > General > Browsing History > Delete… select Temporary Internet files and website files and click delete.
  • Close all IE Browsers and then re deploy your app. Your button will now work again.