Question

I'm trying to show the results of three collections in a page template. How can I make this work?

Was it helpful?

Solution

I found a solution.

Example:

<ul tal:repeat="data context/list-open/queryCatalog">
    <li tal:content="data/Title">title</li>
</ul>

The object "list-open" is the collection.

OTHER TIPS

For a TTW-solution, and if only needed at one location, one can also install Products.ContentWellPortlets, create a page and assign three collection-portlets to the page.

First you will need to create a browserView.

In this browserView, add a method that return the 3 collections merged, you can profit to make some sort, or other processing on the resulting list.

def myNewCompiledCollection(self):
    """ """
    list1 = self.context.list1.queryCatalog()
    list2 = self.context.list2.queryCatalog()
    list3 = self.context.list3.queryCatalog()
    resultList = list1 + list2 + list3
    return resultList

In the browser template just do this :

<ul tal:repeat="data view/myNewCompiledCollection">
    <li tal:content="data/Title">title</li>
</ul>

by just adding the results of each collection to a list you might get duplicate entries in your result.

brains1 = collection1.ueryCatalog()
brains2 = collection2.ueryCatalog()
brains3 = collection3.ueryCatalog()

results = brains1 + brains2 + brains3

afaik you can't use a set for cleaning up your list, since brains for the same object not necessarily are the same objects. so this most probably does not work either:

set(results)

you could however extract the queries from the collections and combine them using Products.AdvancedQuery or - which might be easier to do - turn your result list in a list of uids and do an addiional catalog search:

uids = [brain.UID for brain in results]
results_without_dups = catalog(UID=uids)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top