编辑页面编辑器中的隐藏字段

时间:2013-12-22 07:22:04

标签: sitecore sitecore7 page-editor

我想在Sitecore页面编辑器上编辑一些隐藏字段,例如来自head html部分的元字段。 我该怎么做?我试试

 <sc:FieldRenderer runat="server" ID="scFieldMeta" FieldName="Meta title" /> 

但这不适用于head html部分。

2 个答案:

答案 0 :(得分:2)

Sitecore没有开箱即用的这种功能,但您需要执行以下几个步骤:

  1. 在项目

    下创建
     /sitecore/content/Applications/WebEdit/Edit Frame Buttons 
    

    一个文件夹,你可以命名它:PageProperties。在文件夹下,您必须创建一个新的字段编辑器按钮。 在字段字段上,您需要输入要按管道分别编辑的字段的名称。将是这样的:

        Meta data|Meta title
    
  2. 在项目下:

    /sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Page Editor
    

    您需要创建一个类型为的项目:

     /sitecore/templates/System/Ribbon/Chunk
    

    在新项目下,您必须创建类型的新项目:

     /sitecore/templates/System/Ribbon/Small Button
    

    点击字段中,您将拥有类似

    的内容
     command:executefieldeditor(path=/sitecore/content/Applications/WebEdit/Edit Frame Buttons/Page Properties/Page Properties)  
    

    其中path将指向在第一步创建的项目。

  3. 在此步骤中,您需要创建一个命令。请在include文件夹上创建一个新文件 文件名:CustomCommands.config或者如何使用扩展配置。

    它将包含:

  4.     <?xml version="1.0"?>
        <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
            <sitecore>
                <commands>
                     <command name="command:executefieldeditor" type="yournamespace.ExecuteFieldEditor,yourAssembly"/>
              </commands>
          </sitecore>
     </configuration>
    
    1. 创建班级:
    2. using Sitecore;
      using Sitecore.Data;
      using Sitecore.Data.Items;
      using Sitecore.Diagnostics;
      using Sitecore.Shell.Applications.WebEdit;
      using Sitecore.Shell.Applications.WebEdit.Commands;
      using Sitecore.Text;
      using Sitecore.Web.UI.Sheer;
      using System;
      using System.Collections.Generic;
      using System.Collections.Specialized;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      
      namespace YOURNAMESPACENAME
      {
          public class ExecuteFieldEditor : FieldEditorCommand
          {
              /// <summary>
              /// The fieldname
              /// </summary>
              private const string Fieldname = "Fields";
      
              /// <summary>
              /// The header
              /// </summary>
              private const string Header = "Header";
      
              /// <summary>
              /// The icon
              /// </summary>
              private const string Icon = "Icon";
              /// <summary>
              /// The uriparameter
              /// </summary>
              private const string Uriparameter = "uri";
      
              /// <summary>
              /// The pathparameter
              /// </summary>
              private const string Pathparameter = "path";
      
              /// <summary>
              /// The currentitemisnull
              /// </summary>
              private const string Currentitemisnull = "Current item is null";
      
              /// <summary>
              /// The settingsitemisnull
              /// </summary>
              private const string Settingsitemisnull = "Settings item is null";
      
              /// <summary>
              /// Gets or sets the current item.
              /// </summary>
              /// <value>
              /// The current item.
              /// </value>
              private Item CurrentItem { get; set; }
      
              /// <summary>
              /// Gets or sets the settings item.
              /// </summary>
              /// <value>
              /// The settings item.
              /// </value>
              private Item SettingsItem { get; set; }
      
              /// <summary>
              /// Gets the options.
              /// </summary>
              /// <param name="args">The arguments.</param>
              /// <param name="form">The form.</param>
              /// <returns></returns>
              protected override PageEditFieldEditorOptions GetOptions(ClientPipelineArgs args, NameValueCollection form)
              {
                  EnsureContext(args);
                  return new PageEditFieldEditorOptions(form, BuildListWithFieldsToShow()) { Title = SettingsItem[Header], Icon = SettingsItem[Icon] };
              }
      
              /// <summary>
              /// Ensures the context.
              /// </summary>
              /// <param name="args">The arguments.</param>
              private void EnsureContext(ClientPipelineArgs args)
              {
                  CurrentItem = Database.GetItem(ItemUri.Parse(args.Parameters[Uriparameter]));
                  Assert.IsNotNull(CurrentItem, Currentitemisnull);
                  SettingsItem = Client.CoreDatabase.GetItem(args.Parameters[Pathparameter]);
                  Assert.IsNotNull(SettingsItem, Settingsitemisnull);
              }
      
              /// <summary>
              /// Builds the list with fields to show.
              /// </summary>
              /// <returns></returns>
              private IEnumerable<FieldDescriptor> BuildListWithFieldsToShow()
              {
                  ListString fieldString = new ListString(SettingsItem[Fieldname]);
      
                  return (from field in new ListString(fieldString) where CurrentItem.Fields[field] != null select new FieldDescriptor(CurrentItem, field)).ToList();
              }
          }
      }
      

      您也可以查看post

答案 1 :(得分:2)

我同意Field Editor按钮是正确的解决方案,但您也可以在没有自定义代码的情况下执行此操作:

  1. 在Core DB中,创建一个Field Editor按钮项,如Sitecore Climber所述
  2. 在多行文本字段中输入您的字段,并将其分隔为Sitecore Climber解释
  3. 查找所有网页上显示的子布局,例如Header.ascx或类似的东西。
  4. 在该子布局定义项上,通过“页面编辑器按钮”treelist字段将字段编辑器分配给该UI组件。见图:enter image description here
  5. 在页面编辑器中,当您选择该子布局时,它的上下文功能区将包含一个额外的按钮,允许您编辑这些字段。看这个图片: enter image description here
  6. 当您单击它时,您会看到一个弹出窗口,用于编辑这些以管道分隔的字段。见图:enter image description here