首页 > 解决方案 > 如何在 AEM 的 Teaser 组件中为图像添加 Alt 标签?

问题描述

我想在预告片组件中添加类似于图像组件的 alt 标签。

OOTB 预告片组件使用数据狡猾的资源。

<sly data-sly-template.image="${@ teaser}">
    <div data-sly-test="${teaser.imageResource}" data-sly-resource="${teaser.imageResource}"></div>
</sly>

我可以在 data-sly-resource 上传递属性值吗?

    <div data-sly-test="${teaser.imageResource}" data-sly-resource="${teaser.imageResource @ alt = properties.alt}"></div>

提前致谢。

AEM 6.5 2.6.0 4.1.0

标签: aemsightlyaem-6teaseraem-core-wcm-components

解决方案


在 HTL Sling 实现中,您可以传递参数data-sly-resource(使用请求属性 - 请参阅SLING-5812)。但是,这将要求图像的渲染了解这些并使用它们。

由于您似乎正在使用AEM WCM 核心组件,图像组件将尝试altalt资源的属性中获取属性数据。您可以包装资源并提供自定义alt属性来满足您的需求。


推荐阅读