SharedContent Widget – Displays Sitefinity Shared Content Blocks based on Title

Relates to this blog post: Avoiding uneditable content in your Sitefinity Templates

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SharedContent.ascx.cs" Inherits="SitefinityWebApp.Extensions.Widgets.SharedContent" %>
<asp:Literal ID="ContentLiteral" runat="server" />
using System;
using System.Linq;
using Telerik.Sitefinity;

namespace SitefinityWebApp.Extensions.Widgets
{
    public partial class SharedContent : System.Web.UI.UserControl
    {
        public string ContentTitle { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            var content = App.WorkWith().ContentItems().Where(x => x.Title == ContentTitle).Get().First();

            if (content == null)
            {
                ContentLiteral.Text = "The specified shared content cannot be found.";

                // Yes I know, static content embedded in the code. It's an error message though...
                // The Sitefinity Team would recommend that I create a custom Resource Label in Sitefinity.
                // However, for my purposes this would overcomplicate my example. Feel free to do it though.

            }
            else
            {
                ContentLiteral.Text = content.Content;
            }
        }
    }
}