2017-04-27 61 views

回答

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

+0

没问题,就行了。 –

+0

@Adriaan我更新了答案,希望这会更好。 –

+0

@Mohammad您可以请您建议我需要修改哪些类和xml文件,以便在Device editor对话框之前打开的Layout Details对话框中实现相同的功能。这对我很有帮助 –