Exemple #1
0
        /// <summary>
        /// Returns a newly created model from a Sitecore item
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item">Item to use as the datasource for the model</param>
        /// <param name="initializeModel">If true, the model will be initialized.</param>
        /// <returns></returns>
        public static T Model <T>(Item item, bool initializeModel) where T : class
        {
            // See if there is a mapping
            if (!_templateModelMap.Value.ContainsKey(item.TemplateID.Guid))
            {
                throw new InvalidOperationException(string.Format("Cannot create a model for item {0} because template {1} doesn't have a model", item.Paths.FullPath, item.TemplateName));
            }

            //Get the C# type of the items template
            Type typeToCreate = _templateModelMap.Value[item.TemplateID.Guid];

            //Create it
            T obj = typeToCreate.Assembly.CreateInstance(typeToCreate.FullName) as T;

            //Try to initialize it
            IRenderingModel renderingModel = obj as IRenderingModel;

            if (renderingModel != null && initializeModel)
            {
                //Initialize it.
                renderingModel.Initialize(new Rendering
                {
                    Item = item
                });
            }

            return(obj);
        }
Exemple #2
0
        private void InitializeRenderingModel(T model)
        {
            IRenderingModel renderingModel = model as IRenderingModel;

            if (renderingModel == null)
            {
                return;
            }

            renderingModel.Initialize(Rendering);
        }
Exemple #3
0
 public MediaCarouselRenderingModel(IRenderingModel <IItemWrapper, IHasMediaSelector> model)
     : base(model.PageItem, model.RenderingItem)
 {
 }