Skip to content

Instantly share code, notes, and snippets.

@mikeedwards83
Created April 1, 2012 17:58
Show Gist options
  • Save mikeedwards83/2277395 to your computer and use it in GitHub Desktop.
Save mikeedwards83/2277395 to your computer and use it in GitHub Desktop.
GlassUserControl demo of a page editor user control
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using Glass.Sitecore.Mapper;
using System.Linq.Expressions;
namespace Glass.Demo.Application.Web.Controls
{
public class GlassUserControl<T> : UserControl
{
public GlassUserControl()
{
SitecoreContext = new SitecoreContext();
GlassHtml = new Glass.Sitecore.Mapper.GlassHtml(SitecoreContext);
}
public ISitecoreContext SitecoreContext { get; set; }
Glass.Sitecore.Mapper.GlassHtml GlassHtml { get; set; }
public T Model { get; set; }
public string Field(Expression<Func<T, object>> field)
{
if(field == null) throw new NullReferenceException("No field set");
if (Model == null) throw new NullReferenceException("No model set");
try
{
var result = GlassHtml.Editable<T>(field, Model);
return result;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment