Sitecore布局详细信息表单修改

时间:2017-04-27 08:27:14

标签: sitecore

在sitecore 布局详细信息对话框表单中,我想显示数据源名称以及呈现名称。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

这适用于覆盖一些Sitecore XML控件,并使用以下代码:

private void RenderRenderings(DeviceDefinition deviceDefinition, int selectedIndex, int index)
    {
        Assert.ArgumentNotNull(deviceDefinition, "deviceDefinition");
        ArrayList renderings = deviceDefinition.Renderings;
        if (renderings == null)
        {
            return;
        }
        foreach (RenderingDefinition renderingDefinition in renderings)
        {
            if (renderingDefinition.ItemID != null)
            {
                Item item = Client.ContentDatabase.GetItem(renderingDefinition.ItemID);
                XmlControl xmlControl = Resource.GetWebControl("DeviceRendering") as XmlControl;
                Assert.IsNotNull(xmlControl, typeof(XmlControl));
                System.Web.UI.HtmlControls.HtmlGenericControl htmlGenericControl = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                htmlGenericControl.Style.Add("padding", "0");
                htmlGenericControl.Style.Add("margin", "0");
                htmlGenericControl.Style.Add("border", "0");
                htmlGenericControl.Style.Add("position", "relative");
                htmlGenericControl.Controls.Add(xmlControl);
                string uniqueID = Control.GetUniqueID("R");
                this.Renderings.Controls.Add(htmlGenericControl);
                htmlGenericControl.ID = Control.GetUniqueID("C");
                xmlControl["Click"] = "OnRenderingClick(\"" + index + "\")";
                xmlControl["DblClick"] = "device:edit";
                if (index == selectedIndex)
                {
                    xmlControl["Background"] = "#D0EBF6";
                }
                this.Controls.Add(uniqueID);

                //Get DataSource item path
                var datasource = string.Empty;
                Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
                if (!string.IsNullOrEmpty(renderingDefinition.Datasource))
                {
                    var dsItem = master.GetItem(renderingDefinition.Datasource);
                    if (dsItem != null)
                        datasource = dsItem.Paths.Path;
                }

                if (item != null)
                {
                    xmlControl["ID"] = uniqueID;
                    xmlControl["Icon"] = item.Appearance.Icon;
                    xmlControl["Header"] = item.DisplayName;
                    xmlControl["Placeholder"] = WebUtil.SafeEncode(renderingDefinition.Placeholder);
                    xmlControl["DataSource"] = datasource;
                }
                else
                {
                    xmlControl["ID"] = uniqueID;
                    xmlControl["Icon"] = "Applications/24x24/forbidden.png";
                    xmlControl["Header"] = "Unknown rendering";
                    xmlControl["Placeholder"] = string.Empty;
                    xmlControl["DataSource"] = string.Empty;
                }
                if (renderingDefinition.Rules != null && !renderingDefinition.Rules.IsEmpty)
                {
                    int num = renderingDefinition.Rules.Elements("rule").Count<XElement>();
                    if (num > 1)
                    {
                        System.Web.UI.HtmlControls.HtmlGenericControl htmlGenericControl2 = new System.Web.UI.HtmlControls.HtmlGenericControl("span");
                        if (num > 9)
                        {
                            htmlGenericControl2.Attributes["class"] = "scConditionContainer scLongConditionContainer";
                        }
                        else
                        {
                            htmlGenericControl2.Attributes["class"] = "scConditionContainer";
                        }
                        htmlGenericControl2.InnerText = num.ToString();
                        htmlGenericControl.Controls.Add(htmlGenericControl2);
                    }
                }
                RenderDeviceEditorRenderingPipeline.Run(renderingDefinition, xmlControl, htmlGenericControl);
                index++;
            }
        }
    }

下一步是更新以下文件: \网站\ Sitecore的\壳\覆盖\应用程序\布局\ DeviceEditor.xml \网站\ Sitecore的\壳\覆盖\应用\布局\ DeviceRendering.xml

您可以在以下博文中找到源代码:

http://baraamasri.blogspot.com/2017/03/custom-device-editor_21.html

此外,您可以下载执行此操作的市场模块: https://marketplace.sitecore.net/Modules/C/Custom_Device_Editor.aspx

相关问题