Hello.
I have some content fragments and I need to get the cq:parentPath value, which I see here:
I have tried something like this, but the ContentElement is null
ContentElement test = resultResource.adaptTo(ContentFragment.class).getElement("jcr:content/cq:parentPath");
How can I find this value?
Thanks!
Jeremy
Solved! Go to Solution.
Hi @jeremyc82321732 ,
You are getting this as null because the "getElement()" would return the properties of the content fragment from the data node
"<contentfragmentpath>/jcr:content/data/master".
API References:-
To fetch data from the jcr:content node, you can adapt it to the resource and then read it from the value map properties.
Resource res = resourceResolver.resolve("<path-to-cf>/jcr:content");
ValueMap valueMap = res.getValueMap();
String parentPath = valueMap.get("cq:parentPath", String.class);
Hope this helps!
Regards,
Nitesh
You can resource API itself to read the property of the content fragment.
resultResource.getChild("jcr:content").getValueMap().get("cq:parentPath", String.class)
Hi @jeremyc82321732 ,
You are getting this as null because the "getElement()" would return the properties of the content fragment from the data node
"<contentfragmentpath>/jcr:content/data/master".
API References:-
To fetch data from the jcr:content node, you can adapt it to the resource and then read it from the value map properties.
Resource res = resourceResolver.resolve("<path-to-cf>/jcr:content");
ValueMap valueMap = res.getValueMap();
String parentPath = valueMap.get("cq:parentPath", String.class);
Hope this helps!
Regards,
Nitesh
Views
Like
Replies