Skip to content

Instantly share code, notes, and snippets.

@mikeedwards83
mikeedwards83 / DropdownExample.cs
Created July 22, 2012 09:35
Read and writing data
protected override void OnInit(EventArgs e)
{
btn.Click += new EventHandler(btn_Click);
var form = this.SitecoreContext.GetCurrentItem<Templates.EditableExample>();
base.OnInit(e);
ddlExample.DataSource = form.TreeList;
ddlExample.DataTextField = "Name";
@mikeedwards83
mikeedwards83 / RenderingReferences.cs
Created September 26, 2012 20:59
Loading RenderingReferences using Glass
// First create an attribute that specifies that the property should load the rendering refences
public class SitecoreRenderingsAttribute : AbstractSitecorePropertyAttribute
{
public Device Device { get; set; }
}
//I am using an enumeration to determine which device to load
public enum Device
{
@mikeedwards83
mikeedwards83 / SitecoreRenderingsHandler.cs
Created October 7, 2012 14:36
Fix for SitecoreRenderingsHandler
public class SitecoreRenderingsHandler : AbstractSitecoreDataHandler
{
public override bool WillHandle(SitecoreProperty property, IEnumerable<AbstractSitecoreDataHandler> datas, Dictionary<Type, SitecoreClassConfig> classes)
{
//it was this:
//return property.Attribute is SitecoreRenderingsAttribute && property.Property == typeof(IEnumerable<RenderingReference>);
//should be this
return property.Attribute is SitecoreRenderingsAttribute && property.Property.PropertyType == typeof(IEnumerable<RenderingReference>);
public void ApplicationStart(){
var context = Context.Create(new GlassConfig());
}
context.Load(new SitecoreAttributeConfigurationLoader("Your.Assembly.Name"));
public class CommentController : SitecoreController
{
ISitecoreContext _context;
ISitecoreService _master;
/// <summary>
/// This constructor can be used with dependency injection or unit testing
/// </summary>
/// <param name="context"></param>
public CommentController(ISitecoreContext context, ISitecoreService master)
@inherits System.Web.Mvc.WebViewPage<UserGroup.Models.CommentPage>
@using System.Web.Mvc.Html
@using Sitecore.Mvc
@using Sitecore.Mvc.Contrib.Html;
@Html.Sitecore().Placeholder("webedit")
<div>
<h3>Comments</h3>
@if (Model.CommentAdded)
{
var master = new SitecoreService("master");
var context = master.InstanceContext;
var currentItem = context.GetCurrentItem<Parent>();
var newChild = new Child();
//we use the Name property as the item name when creating an item
newChild.Name = "MyNewChild";
//you can map other properties here
newChild.PageTitle ="My New Child";
Another solution would be to use the Sitecore profiler.
In the PerformanceMonitor.Start add Sitecore.Diagnostics.Profiler.StartOperation(key);
And in the end:
Sitecore.Diagnostics.Profiler.EndOperation(key);
You will then see the processing time outputted into the Sitecore Debug tool.