@Bob: I tried using this method to template the other loops with the same chunk (which had all four placeholders in it):
$einrichtungen = $modx->getCollection('Einrichtung');
foreach($einrichtungen as $einrichtung) {
$einrichtungArray = $einrichtung->toArray();
$output .= $modx->getChunk($tpl,$einrichtungArray);
$standorte = $einrichtung->getMany('Standort');
foreach($standorte as $standort) {
$standortArray = $standort->toArray();
$output .= $modx->getChunk($tpl,$standortArray);
}
$einrichtung_leiters = $einrichtung->getMany('EinrichtungLeiter');
foreach($einrichtung_leiters as $einrichtung_leiter) {
$einrichtung_leiterArray = $einrichtung_leiter->toArray();
$output .= $modx->getChunk($tpl,$einrichtung_leiterArray);
}
$kontakt = $einrichtung_leiter->getOne('Kontakt');
$output .= $modx->getChunk($tpl,$kontakt);
}
$emails = $einrichtung->getMany('Email');
foreach($emails as $email) {
$emailArray = $email->toArray();
$output .= $modx->getChunk($tpl,$emailArray);
}
}
This code outputs only a list of ’Einrichtung’, which didn’t surprise me - I didn’t post this code before because I am kind of ashamed of it

- I now understand that I would probably have to use a seperate chunk for each loop and add some tricky php (like Bruno’s) to help ModX figure out what table in the DB I mean.
@Bruno: Wow, thank you for your detailed help!! I got it set up and learned some basics while doing so.
Now in the meantime I had been experimenting with Smarty for my templating, as I’ve worked with Smarty previously. I actually used the code you posted in the german forum (
http://www.modxcms.de/forum/comments.php?DiscussionID=4075&page=1#Item_5); I only had to change the delimiters to {}.
This is how I set my templating up with Smarty:
Snippet:
<?php
$path = MODX_CORE_PATH . 'components/db_mdnet/';
$result = $modx->addPackage('db_mdnet',$path . 'model/','db_');
global $smarty;
$einrichtungen = $modx->getCollection('Einrichtung');
$einrichtungenArray = array();
foreach($einrichtungen as $einrichtung) {
$einrichtungArray = $einrichtung->toArray();
$einrichtungArray['standort'] = array();
$standorte = $einrichtung->getMany('Standort');
foreach($standorte as $standort) {
$standortArray = $standort->toArray();
$einrichtungArray['standorte'][] = $standortArray;
}
$einrichtungenArray[] = $einrichtungArray;
}
$smarty->assign('einrichtungenArray',$einrichtungenArray);
return $smarty->fetch('chunk:ShowDB_MDNETChunk_Smarty');
And the chunk ShowDB_MDNETChunk_Smarty:
{foreach from=$einrichtungenArray item=einrichtung}
<li>Name: {$einrichtung.name_kurz}</li>
<li>Standorte:
<ul>
{foreach from=$einrichtung.standorte item=standort}
<li>Ort: {$standort.ort}</li>
{/foreach}
</ul>
</li>
{/foreach}
To my programming-dense designer-brain this seems to be a lot easier, especially as this is not an official plugin I’m making but rather a thing that only I will use and change - but I know that templating via Smarty in the frontend is frowned upon. Does anybody have any recommendations as to which method I should decide to use?
And thanks again for all your help, you people are awesome.