Skip to content

Instantly share code, notes, and snippets.

@gabesumner
Created September 23, 2011 21:20
Show Gist options
  • Save gabesumner/1238470 to your computer and use it in GitHub Desktop.
Save gabesumner/1238470 to your computer and use it in GitHub Desktop.
SharedContent Widget - Displays Sitefinity Shared Content Blocks based on Title
<%@ 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;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment