Menu viewlet with plone api

Hi I'm trying to write a viewllet toemulate the menu of plone with a custom css, but i don't know how to use the plone api to fetch the folders and the subfolders and then pass that information to the .pt file.
Than you in advance , and sorry for my english.

1 Like

The context is always your current position in the application. For example, if I'm at localhost:8080/Plone/some-magic-unicorns, then my context would be the object of whatever some-magic-unicorns is. Using this knowledge you can apply it to any situation, if it's a folder you can check the contents of the folder or use the API to limit the results to a certain Content-Type and vice-versa...



api.content.find(context=context, portal_type="Folder")

The first will return the item object and the latter will return a catalog brain. You can get the object from a catalog brain using...

results = api.content.find(context=context, portal_type="Folder")
item = results[0]
obj = item.getObject()

See the plone.api.content documentation.

You need two files. and
in your configure.zcml you need to add 'class=/path/to/yourview'

In the you get the content (like described above)

For example:

def get_folders(self):
      return api.content.find(context=context, portal_type="Folder")

in you '' you use something like

  <div tal:repeat="item view/get_folders">

Plone Foundation Code of Conduct