我想在Sitecore页面编辑器上编辑一些隐藏字段,例如来自head html部分的元字段。 我该怎么做?我试试
<sc:FieldRenderer runat="server" ID="scFieldMeta" FieldName="Meta title" />
但这不适用于head html部分。
答案 0 :(得分:2)
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将指向在第一步创建的项目。
在此步骤中,您需要创建一个命令。请在include文件夹上创建一个新文件 文件名: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(); } } }
您也可以查看post。
答案 1 :(得分:2)
我同意Field Editor按钮是正确的解决方案,但您也可以在没有自定义代码的情况下执行此操作: