App_Code.Controls.WidgetContainer.GetThemeWidgetContainerVirtualPath C# (CSharp) Method

GetThemeWidgetContainerVirtualPath() public static method

Returns the virtual path of where a theme's widget container would expect to be located.
public static GetThemeWidgetContainerVirtualPath ( bool existenceCheck ) : string
existenceCheck bool /// When true, the path to the theme folder to check for the WidgetContainer existence /// is returned. When false, the path to the control that will be loaded is returned. /// If it's a Razor theme, the path will be RazorHost instead of the actual theme folder /// name. ///
return string
        public static string GetThemeWidgetContainerVirtualPath(bool existenceCheck)
        {
            if (existenceCheck)
            {
                // if it's a Razor theme, check if WidgetContainer.cshtml exists.
                string filename = BlogSettings.Instance.IsRazorTheme ? "WidgetContainer.cshtml" : "WidgetContainer.ascx";
                return string.Format("~/themes/{0}/{1}", BlogSettings.Instance.Theme, filename);
            }
            else
            {
                // when existenceCheck == false, the actual file that will be loaded needs to be
                // returned.  if it's a Razor theme, we will load WidgetContainer.ascx in the
                // RazorHost folder.  we assume that the RazorHost folder contains WidgetContainer.ascx.
                return string.Format("~/themes/{0}/WidgetContainer.ascx", BlogSettings.Instance.GetThemeWithAdjustments(null));
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"></see> event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"></see> object that contains the event data.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var zone = this.XmlDocument.SelectNodes("//widget");

            if (zone == null)
            {
                return;
            }

            // This is for compatibility with older themes that do not have a WidgetContainer control.
            var widgetContainerExists      = WidgetContainer.DoesThemeWidgetContainerExist();
            var widgetContainerVirtualPath = WidgetContainer.GetThemeWidgetContainerVirtualPath();

            foreach (XmlNode widget in zone)
            {
                var fileName = string.Format("{0}widgets/{1}/widget.ascx", Utils.RelativeWebRoot, widget.InnerText);
                try
                {
                    var control = (WidgetBase)this.Page.LoadControl(fileName);
                    if (widget.Attributes != null)
                    {
                        control.WidgetId  = new Guid(widget.Attributes["id"].InnerText);
                        control.Title     = widget.Attributes["title"].InnerText;
                        control.ShowTitle = control.IsEditable
                                                ? bool.Parse(widget.Attributes["showTitle"].InnerText)
                                                : control.DisplayHeader;
                    }

                    control.ID   = control.WidgetId.ToString().Replace("-", string.Empty);
                    control.Zone = this.zoneName;

                    control.LoadWidget();

                    // This will return the WidgetContainer with the control in it.
                    var widgetContainer = WidgetContainer.GetWidgetContainer(control, widgetContainerExists, widgetContainerVirtualPath);
                    this.Controls.Add(widgetContainer);
                }
                catch (Exception ex)
                {
                    var lit = new Literal
                    {
                        Text = string.Format("<p style=\"color:red\">Widget {0} not found.<p>", widget.InnerText)
                    };
                    lit.Text += ex.Message;
                    if (widget.Attributes != null)
                    {
                        lit.Text +=
                            string.Format(
                                "<a class=\"delete\" href=\"#\" onclick=\"BlogEngine.widgetAdmin.removeWidget('{0}');return false\" title=\"{1} widget\">X</a>",
                                widget.Attributes["id"].InnerText,
                                labels.delete);
                    }

                    this.Controls.Add(lit);
                }
            }
        }
All Usage Examples Of App_Code.Controls.WidgetContainer::GetThemeWidgetContainerVirtualPath