我想在 Sitecore 页面编辑器上编辑一些隐藏字段,例如 head html 部分的元字段。我该怎么做?我尝试
<sc:FieldRenderer runat="server" ID="scFieldMeta" FieldName="Meta title" />
但这不适用于 head html 部分。
我想在 Sitecore 页面编辑器上编辑一些隐藏字段,例如 head html 部分的元字段。我该怎么做?我尝试
<sc:FieldRenderer runat="server" ID="scFieldMeta" FieldName="Meta title" />
但这不适用于 head html 部分。
Sitecore 没有开箱即用的此类功能,但您需要执行以下几个步骤:
在项目下创建
/sitecore/content/Applications/WebEdit/Edit Frame Buttons
一个文件夹,您可以将其命名为:PageProperties。在文件夹下,您必须创建一个新的字段编辑器按钮。在字段 字段上,您需要输入要按管道单独编辑的字段的名称。会是这样的:
Meta data|Meta title
在项目下:
/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 将指向在第一步创建的项目。
在此步骤中,您需要创建一个命令。请在包含文件夹上创建一个新文件名: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>
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(); } } }
你也可以查看这篇文章。
我同意字段编辑器按钮是正确的解决方案,但您也可以在没有自定义代码的情况下完成这一切: