How do I access the properties of a data-sly-list item in Sightly?

流过昼夜 提交于 2019-12-08 04:26:23

问题


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>

The output ( for a single child ) is

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

I know there is a jcr:title property on the child resource as I have confirmed it using an HTTP call.

How can I access the properties on the child object?


回答1:


The child is a Resource which does not have getProperties() but has getValueMap(), so you should use:

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

Note 1: Colons are allowed in variable names to support typical JCR names like jcr:title.

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



来源:https://stackoverflow.com/questions/33418480/how-do-i-access-the-properties-of-a-data-sly-list-item-in-sightly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!