如何在Sightly中访问数据狡猾列表项的属性? [英] How do I access the properties of a data-sly-list item in Sightly?
问题描述
我将Sightly与Sling 8(不是AEM)配合使用.我有以下模板:
I am using Sightly with Sling 8 ( not AEM ). I have the following template:
<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调用确认了它.
I know there is a jcr:title property on the child resource as I have confirmed it using an HTTP call.
如何访问child
对象上的属性?
How can I access the properties on the child
object?
推荐答案
The child
is a Resource which does not have getProperties() but has getValueMap()
, so you should use:
${child.valueMap.jcr:title || 'no title'}
注1:变量名称中允许使用冒号来支持典型的JCR名称,例如jcr:title
.
Note 1: Colons are allowed in variable names to support typical JCR names like jcr:title
.
注2:仅自Sling API 2.7.0捆绑包以来,getValueMap()才可用,以前只能使用resource.adaptTo(ValueMap.class)
,而表达式语言显然不支持,因此需要以下解决方法:
Note 2: getValueMap() is only available since Sling API 2.7.0 bundle, previously only resource.adaptTo(ValueMap.class)
was possible, which the expression language in sightly does not support, and this workaround was required: AEM 6.0 Sightly Child Nodes
这篇关于如何在Sightly中访问数据狡猾列表项的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!