sitecore - 如何使用附加属性扩展 Glass.Mapper.Sc.Fields.Image?

标签 sitecore glass-mapper sitecore-mvc

我将 Sitecore 媒体库图像的裁剪信息存储在添加到 /sitecore/templates/System/Media/Unversioned/Image 模板的字段中。

我想访问此字段以及 Glass.Mapper.Sc.Fields.Image 复杂字段类型中存在的所有其他属性,以便我可以继续使用 在我看来,GlassHtml.RenderImage()

我最初尝试从该类继承并不成功 - 它似乎破坏了映射行为 - 所以我想知道是否有另一种方法可以使用附加属性来扩展此类?

这是我尝试过的:

[SitecoreType(AutoMap = true)]
public class MyImage : Glass.Mapper.Sc.Fields.Image
{
    public virtual string CropInfo { get; set; }
}

最佳答案

您将需要实现自定义数据处理程序来映射附加字段。

我将创建一个继承自标准图像数据处理程序的数据处理程序:

https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/DataMappers/SitecoreFieldImageMapper.cs

然后自定义GetFieldSetField

创建自定义数据处理程序后,您需要将其注册到 Windsor 容器。请参阅教程 19 了解如何执行此操作:

http://glass.lu/docs/tutorial/sitecore/tutorial19/tutorial19.html

重要部分:

public static void CastleConfig(IWindsorContainer container){
        var config = new Config();

        container.Register(
          Component.For < AbstractDataMapper>().ImplementedBy<TweetsDataHandler>().LifeStyle.Transient
          );

        container.Install(new SitecoreInstaller(config));
} 

关于sitecore - 如何使用附加属性扩展 Glass.Mapper.Sc.Fields.Image?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18748665/

相关文章:

Sitecore - 从发布弹出窗口中隐藏 "Publish Subitems"

sitecore - 清除使用 Glass.Mapper.Sc BeginRenderLink 渲染的 Sitecore 链接字段会删除包装字段

sitecore - 是否可以在 Sitecore 页面编辑器 "component navigator"中为占位符、组件和编辑框架定义不同的图标?

sitecore - Sitecore MultiSite 中的数据源限制

excel - 将 Sitecore 项目列表导出为 Excel(或其他格式)

google-analytics - 通过Sitecore CMS将HTML代码插入页面模板

c# - Sitecore/GlassMapper 获取页面

Sitecore 7.x 测试(a/b,多变量)MVC

powershell - 使用 Sitecore Powershell 扩展更新媒体项目

c# - 使用 Sitecore.FakeDb 的单元测试在 GetItem 上抛出 Sitecore.Nexus 实例化错误