2

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

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

但这不适用于 head html 部分。

4

2 回答 2

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. 在此步骤中,您需要创建一个命令。请在包含文件夹上创建一个新文件名:CustomCommands.config 或者您希望如何使用扩展配置。

    它将包含:

    <?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. 创建您的课程:
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();
        }
    }
}

你也可以查看这篇文章

于 2013-12-22T07:50:25.213 回答
2

我同意字段编辑器按钮是正确的解决方案,但您也可以在没有自定义代码的情况下完成这一切:

  1. 在 Core DB 中,按照 Sitecore Climber 的说明创建字段编辑器按钮项
  2. 在多行文本字段中输入您的字段,用管道分隔它们,如 Sitecore Climber 解释的那样
  3. 找到出现在所有页面上的子布局,例如 Header.ascx 或类似的东西。
  4. 在该子布局定义项上,通过“页面编辑器按钮”树形列表字段将字段编辑器分配给该 UI 组件。看这张图片:在此处输入图像描述
  5. 在页面编辑器中,当您选择该子布局时,它的上下文功能区将包含一个额外的按钮,允许您编辑这些字段。看这张图片: 在此处输入图像描述
  6. 当您单击它时,您会弹出一个窗口来编辑那些以竖线分隔的字段。看这张图片:在此处输入图像描述
于 2013-12-22T17:16:51.903 回答