Display content from Reusable HTML list in a MasterPage

Tags: SharePoint

This is as useful as it is simple!

Having a footer for example in your master page without the overhead of being responsible for its maintenance.

Here is a simple WebControl that you can reference in your master page and supply a key.


Note: You might want to handle the exception better!!

public class DisplayReusableContent : WebControl
    public string ContentTitle { get; set; }

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
            SPList rcl = SPContext.Current.Site.RootWeb.Lists["Reusable Content"];
            SPQuery q = new SPQuery
                Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + ContentTitle + "</Value></Eq></Where>"
            var items = rcl.GetItems(q);
            if (items != null && items.Count > 0)
                // Should only be 1!
        catch (Exception ex)


Register Control

<%@ Register TagPrefix="my" Namespace="$Your-Namespace" Assembly="$Assembl" %>

Use the Control

<my:DisplayReusableContent ContentTitle="Copyright" runat="server" id="ruc1" />

And that’s it – not life changing, but one for the tool-bag!


comments powered by Disqus