Sitecore Swamp

Dive in the Sitecore Swamp

NAVIGATION - SEARCH

Learning Glass.Mapper

  1. Associate mapped class need load the assembly which contains the mapped class.
    public static  class GlassMapperScCustom
    {
    	...
    
    	public static IConfigurationLoader[] GlassLoaders(){			
    			
    		/* USE THIS AREA TO ADD FLUENT CONFIGURATION LOADERS
                * 
                * If you are using Attribute Configuration or automapping/on-demand mapping you don't need to do anything!
                * 
                */
     
            return new IConfigurationLoader[] { new AttributeConfigurationLoader("Choice.Domain.Sitecore") };
    	}
    	...
    }
  2. Auto mapping process the string value, for example, stripping off hyphen with space. To fix this, always specify FieldType:
        [SitecoreType(TemplateId = "{A82DA878-D247-4124-927F-A01C28CD6CAB}"AutoMap = true)]
        public class ProductField
        {
            [SitecoreField(FieldName = "Key"FieldType = SitecoreFieldType.SingleLineText)]
            public virtual string Key { getset; }
        }

Model - Glass.Mapper - Sitecore.Item

The dream tool to map between model class to Sitecore item. Check it out: http://glass.lu/

Step 1, Sitecore Item:

Step 2. Model class
   public class HomePage
    {
        public virtual string Title { get; set; }
        public virtual string MainBody { get; set; }
    }

Step 3. Sublayout Code-behind:
    public partial class HomePageSublayout : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var context = new SitecoreContext();
            Model = context.GetCurrentItem<HomePage>();
        }
        public HomePage Model { get; set; }
    }