【问题标题】:Glass mapper Render Image data attributesGlass mapper 渲染图像数据属性
【发布时间】:2023-03-22 06:58:01
【问题描述】:

我正在尝试使用 RenderImage 渲染图像字段。我需要图像中的一些数据属性,但我似乎无法弄清楚如何实现它。这个我试过了,还是不行

@RenderImage(image, x => x.Image, new RenderingParameters("data-protect=true"), isEditable: true)   

谢谢

【问题讨论】:

    标签: c# sitecore glass-mapper


    【解决方案1】:

    虽然上面的答案会起作用,但我将在未来删除 ImageParameters 支持并转向只支持匿名类型:

    @RenderImage(image, x => x.Image, new { Width = 100}, isEditable: true)
    

    这种变化的原因是像 ImageParameters 这样的强类型类是非常有限的。匿名类型也是与其他框架一起执行此操作的常用方式,因此它适合其他所有人正在做的事情。

    更新为包含数据属性的呈现:

    @RenderImage(image, x => x.Image, new { data_protect = "true"}, isEditable: true)
    

    【讨论】:

    • 问题在于我无法开始工作的数据保护。因此,如果您可以添加对连字符命名属性的支持,那就太好了。
    • Gabbar - 最新的夜间版本已解决此问题。可以使用“data_id”获取“data-id”,方式与MVC相同。
    【解决方案2】:

    试试这样:

    @RenderImage(image, x => x.Image, new ImageParameters { Width = 100}, isEditable: true)
    

    截至最新版本的 Glass - 唯一可能的解决方案是

    @RenderImage(image, x => x.Image, new { Width = 100}, isEditable: true)
    

    你也可以看看-TUTORIAL 16 - RENDERING IMAGES

    【讨论】:

    • 我已经编辑了我的问题。 data-protect 是一个自定义属性。我怎样才能让它显示出来?
    • @Gabbar 我认为不创建一个新类而不是从 AbstractParameters 扩展是不可能的。您可以在此处检查默认的 ImageParameters。只需使用所需的数据实现您的自定义类。 github.com/mikeedwards83/Glass.Mapper/blob/master/Source/…。另一种选择是手动渲染图像(使用 src 属性)并仅在页面编辑器模式下将其显示为可编辑。
    • 好吧,这是有道理的。我会尝试这两种方法。
    • @tahatmat 更新了! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多