GlassMapper渲染自定义链接字段
问题描述:
我们对Sitecore的8.1更新3和玻璃映射器4.2.1.188GlassMapper渲染自定义链接字段
对于普通链路领域的经验丰富的编辑和正常模式下其工作的罚款。
我们重复了核心数据库中的General Link字段并删除了“Javascript”菜单项。这是我们为自定义链接字段进行的唯一更改。
这使得字段在体验编辑器模式中消失。它在正常模式下很好。
@RenderLink(x => x.CallToActionButton, new { @class = "c-btn c-btn--strong c-btn--large" }, isEditable: true)
编辑1:
当我使用Sitecore的现场呈示其所有的好。
@Html.Sitecore().Field(FieldIds.HomeCallToActionButton, new { @class = "c-btn c-btn--strong c-btn--large" })
任何建议,将不胜感激。
答
您出现问题的原因是,Sitecore在生成经验编辑器中显示的代码时检查字段类型键。如果
Sitecore.Pipelines.RenderField.GetLinkFieldValue
类检查字段类型密钥是link
或general link
和你写的,你抄袭了原General Link
字段,以便您的字段的名称是Custom Link
或类似的东西。这意味着您的案例中字段类型密钥是custom link
(字段类型名称小写)。 SkipProcessor
方法将custom link
与字段类型键进行比较,并且由于它不同,处理器会忽略您的字段。
您不能简单地将您的字段重命名为General Link
并将其放在Field Types/Custom
文件夹中导致Sitecore不保留字段类型的ID(它存储字段类型键)。
你可以做的是覆盖Sitecore.Pipelines.RenderField.GetLinkFieldValue
类和喜欢它的方法之一:
using Sitecore.Pipelines.RenderField;
namespace My.Assembly.Namespace
{
public class GetLinkFieldValue : Sitecore.Pipelines.RenderField.GetLinkFieldValue
{
/// <summary>
/// Checks if the field should not be handled by the processor.
/// </summary>
/// <param name="args">The arguments.</param>
/// <returns>true if the field should not be handled by the processor; otherwise false</returns>
protected override bool SkipProcessor(RenderFieldArgs args)
{
if (args == null)
return true;
string fieldTypeKey = args.FieldTypeKey;
if (fieldTypeKey == "custom link")
return false;
return base.SkipProcessor(args);
}
}
}
,而是注册它的原班:
<sitecore>
<pipelines>
<renderField>
<processor type="Sitecore.Pipelines.RenderField.GetLinkFieldValue, Sitecore.Kernel">
<patch:attribute name="type">My.Assembly.Namespace.GetLinkFieldValue, My.Assembly</patch:attribute>
</processor>
</renderField>
</pipelines>
</sitecore>
@马雷克 - Musieklak Sitecore的被渲染字段权限。当我使用Sitecore Field helper时,它在Experience编辑器中都很好用。它仅在GlassMapper中发生? –
什么是FieldTypeKey? –
字段类型键=字段类型名称小写。你有没有尝试过我上面写的? –