Tag Archives: MasterPage

Reusable Content Control – Sharepoint 2013 MasterPage

SharePoint-2013
Although the Reusable Content list works well for adding content to content placeholders in a publishing page, there are times when I want to use it to store reusable content that should show up in my master page or in page layouts. For instance, I’d like the copyright message that appears in the footer to be maintained by content owners, so that each time a new year rolls by, they can update the date in the footer without needing to get a developer involved to update the master page.
This is a control I’ve developed that retrieves a particular item from the Reusable Content list by the item’s title, and displays it. It retrieves the item by a simple CAML query.
using System;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
namespace BB.SP2010.WebControls
{
public class ReusableContentControl : WebControl
{
private string reusableContentListItemTitle;
      public string ReusableContentListItemTitle
{
set { reusableContentListItemTitle = value; }
}
      protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
SPWeb rootWeb = SPContext.Current.Site.RootWeb;
SPList reusableContentList = rootWeb.Lists[“Reusable Content”];
         SPQuery query = new SPQuery();
query.Query = String.Format(“<Where><Eq><FieldRef Name=’Title’/><Value Type=’Text’>{0}</Value></Eq></Where>”,
reusableContentListItemTitle);
SPListItemCollection listItems = reusableContentList.GetItems(query);
if (listItems.Count > 0)
{
SPListItem listItem = listItems[0];
            Literal reusableContent = new Literal();
reusableContent.Text = listItem[“Reusable HTML”].ToString();
this.Controls.Add(reusableContent);
}
         base.RenderChildren(writer);
}
}
}
To use this control, first add a reference to the assmebly in your page, like this:
<%@ Register Tagprefix=”CustomWebControls” Namespace=”BB.SP2010.WebControls” Assembly=”BB.SP2010.WebControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2f91cfdda5cd365b” %>
Next, add the control to your page, passing in the title of the Reusable List list item you want to render to the page:
<CustomWebControls:ReusableContentControl runat=”server” ID=”copyrightControl” ReusableContentListItemTitle=”Copyright”/>
I’m not caching the results because, if you have caching turned on on your Publishing site, the CAML query itself should be cached.
Ref : savtechsol

Cannot see Master Pages in SharePoint Designer 2013 In root site

SharePoint-2013

If you just want to edit the master page without fixing the missing items in the sidebar, you can navigate to _catalogs/masterpage through the “All Files” section in SharePoint Designer.

On the other hand, if you want to fix it, here’s how I managed to do it:

We were facing the same problem in one of our SharePoint 2013 installations. I searched for that and I only found answers saying that I’d need to activate the publishing feature in the site collection scope, however that was not the problem since it was already activated.

Later I found out that the “Lists and Libraries” section in the Site Objects would not show any results. The problem is that we had a list in the site that was using a list template from an old solution that was not installed anymore, causing ListData.svc — a web service used by SharePoint Designer — to crash. You can see more here: Why don’t Lists and Libraries show up in SharePoint Designer?

After I deleted that list though the SharePoint Management Shell, not only the lists started to show up in the Lists and Libraries section, as also the Master Pages and Page Layouts sections reappeared.

Ref : Sharepoint StackExchange

Creating flat site collection breadcrumb for SharePoint sites

SharePoint has several ways to navigate through site hierarchy and many users are used to breadcrumb to see where they are etc. Some consider collapse breadcrumb “folder” control not too intuitive and you may be asked to define your breadcrumb more explicitly or as a “flat” set of links.

To save yourself some time from custom development of the breadcrumb you can take the breadcrumb “folder” content and render it in a flat format. To do that we will take the SharePoint:ListSiteMapPath control which lives on each masterpage and place it right inside s4-titletext in your main masterpage:

Here is the code:

<sharepoint:ListSiteMapPath ID="ListSiteMapPath11" runat="server" 
SiteMapProviders="SPSiteMapProvider" 
RenderCurrentNodeAsLink="false" 
PathSeparator="" CssClass="s4-breadcrumb" 
NodeStyle-CssClass="s4-breadcrumbNode" 
CurrentNodeStyle-CssClass="s4-breadcrumbCurrentNode" 
RootNodeStyle-CssClass="s4-breadcrumbRootNode" 
NodeImageOffsetX=0 
NodeImageOffsetY=582 
NodeImageWidth=16 
NodeImageHeight=16 
NodeImageUrl="/_layouts/images/fgimg.png" 
RTLNodeImageOffsetX=0 
RTLNodeImageOffsetY=582 
RTLNodeImageWidth=16 
RTLNodeImageHeight=16 
RTLNodeImageUrl="/_layouts/images/fgimg.png" 
HideInteriorRootNodes="true" 
SkipLinkText=""/>

Now you just need to adjust the CSS to flatten the structure; in here I’ll add the following CSS into the masterpage

.s4-title-inner .s4-titletext

{ margin-bottom: 3px; }

.s4-title-inner .s4-titletext ul, .s4-title-inner .s4-titletext ul li

{ display: inline; }

.s4-title-inner .s4-titletext ul.s4-breadcrumbRootNode, .s4-title-inner .s4-titletext ul.s4-breadcrumbNode

{ margin-left: 5px; }

This CSS is specific to the breadcrumb in s4-titletext and will not affect other elements on the masterpage.

Reference : Creating flat site collection breadcrumb for SharePoint sites

how to apply custom master page to application pages

I came across a position, where i have an application page developed for user requirement and the user desires the look and feel of this page to me similar to other pages in the context.

I tried so many alternatives but didn’t get prospered; I found the right to use the default.master or custom master page for application pages.

First thing is that if you need to use a masterpage from the site context, you want to have the similar content placeholders as are expected by the master page.

Master pages can be loaded dynamically. This can be done by assigning a master page file to the MasterPageFile property in the Page object. This property may only be assigned in the Page PreInit event, this is the first event executed page execution lifecycle.

Copy and paste this below code in your custom application page and deploy the assembly to GAC and see, it should work now.

protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
SPWeb TestWeb = SPControl.GetContextSite(Context).OpenWeb();
string strUrl = TestWeb.ServerRelativeUrl + “/_catalogs/masterpage/Test.master”;
this.MasterPageFile = strUrl;
}

Where “Test.master” has to be stored in master page gallery of the site.

Probably you may get a memory leak for SPWeb object , so you can use this simple code instead of the above

protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.MasterPageFile = SPContext.Current.Web.MasterUrl;
}