Adding a WebPart to a SharePoint 2013 Master Page

mtngeekuk picture mtngeekuk · Sep 18, 2013 · Viewed 14k times · Source

Have looked on here plenty but this is the first time I've asked a question, so please bear with me.

Within my SharePoint site collection, I have a list of links to other systems within the business - this list is hidden to all users apart from Admins. There is a department column, indicating the department each link belongs to. There are two filter columns in this list - one is "active", the other is "show in System Links".

On each departmental page, there is a Content by Query Web Part (CQWP) showing the list, filtering to show: - Specific departmental links - Only where active

Separately to this, there is another CQWP on the homepage of the site collection showing all those links that have "show in System Links" ticked.

What this allows me to do is if for some reason a system is offline for maintenance, I can change the "active" value in the list and all links will vanish (preventing users going to the external system). It also allows me to add prominence to a link on the homepage if it's of particular focus that day / week / month (i.e. link to HR system to book leave if there's a leave deadline coming up).

What I want to do is move the homepage System Links CQWP to under the Quick Links on the left hand side, so they appear on every page. I did this with no problems in 2010, by literally dragging and dropping in the visual view for the master page, but seem to be struggling in 2013.

I've tried following the advice here:

http://ramisharepointblog.blogspot.co.uk/2013/01/how-to-add-custom-webpart-within.html

When I add these to the .html master file, I get an error message saying that I need to change the file extension of my HTML file to something else.

I get this message whether I copy and paste the code, or whether I use the button "insert web part". (Obviously doing this in SPD 2013)

When I do this, it seems to lose the reference to the .master file (or explode!) As an alternative, I tried adding the code into the .master file, but of course I can't do this, as it won't let me move / edit / copy a .master file.

Any help in this would be MUCH appreciated, as I seem to be banging my head against a wall here.

Answer

banana picture banana · Oct 17, 2013

On SharePoint 2013 you can not add the Web Parts to the master page the same way of 2010.
Please use the Design Manager -> Snippet Gallery.

In short:
You must wrap the Register tag with: <!--SPM: register tag -->
Like this:

<!--SPM:<%@Register Tagprefix="Publishing" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>-->

You should wrap the opening tag of your Web Part with: <!--MS: tag -->
And the closing tag with: <!--ME: tag -->
The Web Part would look like this:

<!--MS:<asp:SiteMapDataSource ShowStartingNode="True" SiteMapProvider="SPNavigationProvider" ID="topSiteMap" runat="server" StartingNodeUrl="sid:1002">-->
…
<!--ME:</asp:SiteMapDataSource>-->

(Snippet Gallery will automatically create the tags in the right way and you can copy it to your master page.)