How to use 'contentlisting' with 'path'

In the docs, it says:

In Python a ContentListing of a particular folder's contents can be fetched by using:

>>> path.to.your.folder.restrictedTraverse('@@contentlisting')()

In my case, the path is 'Plone/folder/folder-1', but is it (really) supposed to be working like this? (it does not)

 Plone.folder.folder-1.restrictedTraverse("@@contentlisting")()

Try

Plone.folder["folder-1"].restrictedTraverse("@@contentlisting")()

you could also use plone.api

folder = api.content.get(path='/folder/folder-1')
listing = api.content.get_view(name="contentlisting", context=folder)

Thanks, works like a charm.

One note: I got 'not callable error', so my code is now :slight_smile:

listing = api.content.get_view(name="contentlisting", context=folder)
2 Likes