public override void PreRender(WidgetContext context) { context.Model = new Article { Title = "Introducing the widget view feature", Content = "Do you like it?" }; }
public virtual void PreRender(WidgetContext context) { }
private void AddWidgetControl(LocatedWidget locatedWidget, Zone zone) { var plugin = PluginManager.FindEnabledPlugin(locatedWidget.PluginName); if (plugin == null) return; var widget = plugin.FindWidget(locatedWidget.WidgetName); if (widget == null) return; if (!String.IsNullOrEmpty(locatedWidget.ViewName)) { object model = null; if (widget.WidgetControllerType != null) { var context = new WidgetContext { Page = locatedWidget.Page, LocatedWidget = locatedWidget }; var controller = (IWidgetController)Activator.CreateInstance(widget.WidgetControllerType); controller.PreRender(context); model = context.Model; } // render var view = widget.Views.Find(v => v.Name == locatedWidget.ViewName); var viewPath = Server.MapPath(UrlUtil.Combine(view.VirtualPath, "Default" + view.Extension)); var viewContent = File.ReadAllText(viewPath, System.Text.Encoding.UTF8); var modelType = model == null ? null : model.GetType(); var html = Engine.Razor.RunCompile(viewContent, widget.Plugin.Name + "." + widget.Name + "." + view.Name, modelType, model, null); var control = new LiteralControl(html); Controls.Add(control); } else { var control = WidgetControlLoader.Load(widget, Page, IsInDesignMode); Controls.Add(control); var widgetControl = control as WidgetControlBase; if (widgetControl == null) { // Check if the widget control is using output cache var cachingControl = control as PartialCachingControl; if (cachingControl != null) { widgetControl = cachingControl.CachedControl as WidgetControlBase; } } if (widgetControl != null) { widgetControl.LocatedWidget = locatedWidget; widgetControl.Widget = widget; widgetControl.IsInDesignMode = IsInDesignMode; widgetControl.WidgetAttributes.AddRange(locatedWidget.Attributes); } } }