【问题标题】:How do I access the properties of a data-sly-list item in Sightly?如何在 Sightly 中访问 data-sly-list 项的属性?
【发布时间】:2016-01-29 20:17:36
【问题描述】:

我将 Sightly 与 Sling 8(不是 AEM)一起使用。我有以下模板:

<div data-sly-list.child="${resource.listChildren}">
    ${child.name}  |  ${child.path} | ${child.properties['jcr:title'] || 'no title'} 
</div>

输出(对于单个孩子)是

hello_world | /content/blog/posts/hello_world | no title 

我知道子资源上有一个 jcr:title 属性,因为我已使用 HTTP 调用确认它。

如何访问child 对象的属性?

【问题讨论】:

    标签: sling sightly


    【解决方案1】:

    child 是一个 Resource,它没有 getProperties() 但有 getValueMap(),所以你应该使用:

    ${child.valueMap.jcr:title || 'no title'}
    

    注意 1:变量名称中允许使用冒号以支持典型的 JCR 名称,例如 jcr:title

    注意 2:getValueMap() 仅在 Sling API 2.7.0 捆绑包中可用,以前只有 resource.adaptTo(ValueMap.class) 可用,表达式语言显然不支持,需要此解决方法:AEM 6.0 Sightly Child Nodes

    【讨论】:

      猜你喜欢
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      相关资源
      最近更新 更多