How do I access the properties of a data-sly-list

2019-06-03 21:54发布

问题:

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



标签: sling sightly