【问题标题】:Edit hidden fields in page editor在页面编辑器中编辑隐藏字段
【发布时间】:2013-12-22 07:22:03
【问题描述】:

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

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

但这不适用于 head html 部分。

【问题讨论】:

    标签: sitecore sitecore7 page-editor


    【解决方案1】:

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

    1. 在项目下创建

       /sitecore/content/Applications/WebEdit/Edit Frame Buttons 
      

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

          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)  
      

      路径将指向在第一步创建的项目。

    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();
            }
        }
    }
    

    您也可以查看此post

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多