This solution was initially provided to the MODx user Sharkbait who asked „how to pull each first/newest document from different containers”.
I am pasting here the directory structure of Sharkbait’s photo gallery that the solution was designed for:
Example of directory structure
GalleryOverview (id=10)
Portraits
Portrait 1
Portrait 2
...
Landscape
Landscape 1
...
Black & White
Black & White 1
...
...
We need to retrieve in a single and concise step newest documents from each folder under „GalleryOverview” — one latest document for each subfolder. This might be done as follows:
Main Ditto call
[[Ditto? &parents=`10` &depth=`2` &display=`all` &filter=`isfolder,1,1` &tpl=`newest-doc`]]
This call of Ditto collects all subfolders under „GalleryOverview” and these collected subfolders are subsequently explored by „newest-doc” chunk for the latest document:
Content of „newest-doc” chunk
[[Ditto? &parents=`[+id+]` &depth=`1` &display=`1` &filter=`isfolder,0,1` &tpl=`doc-template` &sortBy=`createdon` &sortDir=`DESC`]]
- Required fields are marked with *.
- Comments are published after the approval of the site moderator, who is a human rather than a wind-fast computer program so please be patient. Off-topic comments are definitely removed.
| Enter this code into the appropriate field of the form while submitting an e-mail or a comment. If you have trouble with reading it, generate another... |


