Zugehörige Kinderartikel ausgeben, Contao 5.3, MM 2.4
Hallo,
ich habe Elterntabelle (Personen) und eine Kindertabelle (Artikel). Nun versuche ich im Template metamodel_prerendered_persons.html5, die ich für den Rendering für Frontend einstellte, die Personen und die zu ihnen zugehörigen Artikel auszugeben. Mein Template sieht momentan so aus.
Leider kommen die Artikel nicht richtig aus, d.h. dass es nur rauskommt.
HTML-Code:
<div class="item article first even" id="article_7" data-id="article_7"></div>
Außerdem stimmt es noch nicht, welche Artikel zu welcher Person rauskommen. Wahrscheinlich ist die Abfrage noch nicht richtig. Weiß jemand, was da noch nicht stimmt?
PHP-Code:
<?php
$translator = \Contao\System::getContainer()->get('translator');
// Debug items.
if (\Contao\System::getContainer()->get('kernel')->isDebug()) {
dump($this->data);
}
?>
<?php if (count($this->data)): ?>
<div class="layout_full">
<?php foreach ($this->data as $arrItem): ?>
<?php $this->block('item'); ?>
<div class="item person <?= $arrItem['class'] ?>" id="person_<?= $arrItem['raw']['id'] ?>" data-id="person_<?= $arrItem['raw']['id'] ?>">
<?php
// Name der MetaModel Tabelle
$modelName = 'mm_person_articles';
$renderId = $arrItem['raw']['id'];
$factory = $this->getContainer()->get('metamodels.factory');
$model = $factory->getMetaModel($modelName);
$filter = $model->getEmptyFilter();
$items = $model->findByFilter($filter);
$renderFactory = $this->getContainer()->get('metamodels.render_setting_factory');
$articleItems = $items->parseAll('html5', $renderFactory->createCollection($model, $renderId));
?>
<?php foreach ($arrItem['attributes'] as $field => $name): ?>
<?php if ((null !== ($value = $arrItem[$this->getFormat()][$field] ?? null)) ||
(null !== ($value = $arrItem['text'][$field] ?? null))): ?>
<div class="field <?= $field ?> <?php if ($field == 'longtext'): ?>modal<?php endif ?>">
<?php if ($field == 'longtext'): ?><div class="modal-inner"><?php endif ?>
<?php if ($field == 'longtext'): ?>
<div class="modal-trigger-buttons">
<div class="modal-trigger-buttons_inner">
<button class="modal-close-button">
<svg width="100%" height="100%" viewBox="0 0 119 119" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;">
<g transform="matrix(1,0,0,1,-156,-1)">
<g id="close-button" transform="matrix(1,0,0,1,15.4793,-1693.22)">
<rect x="141" y="1695" width="117.833" height="117.833" style="fill:none;"/>
<g id="close" transform="matrix(3.79222,0,0,3.79222,137.457,1691.35)">
<g>
<g>
<path d="M16.47,32.036C7.905,32.036 0.962,25.08 0.962,16.5C0.962,7.92 7.905,0.964 16.47,0.964C25.035,0.964 31.979,7.92 31.979,16.5C31.979,25.08 25.035,32.036 16.47,32.036ZM16.47,30.036C23.932,30.036 29.979,23.975 29.979,16.5C29.979,9.025 23.932,2.964 16.47,2.964C9.009,2.964 2.962,9.025 2.962,16.5C2.962,23.975 9.009,30.036 16.47,30.036Z" style="fill:rgb(107,50,179);"/>
</g>
</g>
<path d="M8.986,9.002L23.955,23.998" style="fill:none;fill-rule:nonzero;stroke:rgb(107,50,179);stroke-width:2px;"/>
<path d="M23.955,9.002L8.986,23.998" style="fill:none;fill-rule:nonzero;stroke:rgb(107,50,179);stroke-width:2px;"/>
</g>
</g>
</g>
</svg>
</button>
<button class="modal-prev-button">
<svg width="100%" height="100%" viewBox="0 0 119 118" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;">
<g transform="matrix(1,0,0,1,-305,0)">
<g id="prev-button" transform="matrix(1,0,0,1,164.676,-1695)">
<rect x="141" y="1695" width="117.833" height="117.833" style="fill:none;"/>
<g id="preview" transform="matrix(3.79222,0,0,3.79222,-39.3413,1691.35)">
<g>
<g>
<path d="M63.092,32.036C54.529,32.036 47.583,25.078 47.583,16.5C47.583,7.922 54.529,0.964 63.092,0.964C71.654,0.964 78.6,7.922 78.6,16.5C78.6,25.078 71.654,32.036 63.092,32.036ZM63.092,30.036C70.551,30.036 76.6,23.972 76.6,16.5C76.6,9.028 70.551,2.964 63.092,2.964C55.633,2.964 49.583,9.028 49.583,16.5C49.583,23.972 55.633,30.036 63.092,30.036Z" style="fill:rgb(107,50,179);"/>
</g>
</g>
<path d="M66.95,8.51L59.436,16.259L66.95,24.085" style="fill:none;fill-rule:nonzero;stroke:rgb(107,50,179);stroke-width:2px;"/>
</g>
</g>
</g>
</svg>
</button>
<button class="modal-next-button">
<svg width="100%" height="100%" viewBox="0 0 119 119" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;">
<g transform="matrix(1,0,0,1,-452,-2)">
<g id="next-button" transform="matrix(1,0,0,1,311.769,-1692.43)">
<rect x="141" y="1695" width="117.833" height="117.833" style="fill:none;"/>
<g id="next" transform="matrix(3.79222,0,0,3.79222,-211.652,1691.35)">
<g>
<g>
<path d="M108.53,32.036C99.967,32.036 93.021,25.078 93.021,16.5C93.021,7.922 99.958,0.964 108.53,0.964C117.102,0.964 124.038,7.922 124.038,16.5C124.038,25.078 117.092,32.036 108.53,32.036ZM108.53,30.036C115.989,30.036 122.038,23.972 122.038,16.5C122.038,9.028 115.998,2.964 108.53,2.964C101.062,2.964 95.021,9.028 95.021,16.5C95.021,23.973 101.071,30.036 108.53,30.036Z" style="fill:rgb(107,50,179);"/>
</g>
</g>
<path d="M104.681,8.51L112.195,16.259L104.681,24.085" style="fill:none;fill-rule:nonzero;stroke:rgb(107,50,179);stroke-width:2px;"/>
</g>
</g>
</g>
</svg>
</button>
</div>
</div>
<?php endif; ?>
<?= $value ?>
<?php if ($field == 'intro'): ?>
<button class="button modal-trigger">
<svg width="100%" height="100%" viewBox="0 0 118 118" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<g id="button-trigger" transform="matrix(1,0,0,1,-141,-1695)">
<rect x="141" y="1695" width="117.833" height="117.833" style="fill:none;"/>
<clipPath id="_clip1">
<rect x="141" y="1695" width="117.833" height="117.833"/>
</clipPath>
<g clip-path="url(#_clip1)">
<g id="trigger-button1" serif:id="button-trigger" transform="matrix(0.75,0,0,0.75,34.8749,-2203.63)">
<g transform="matrix(5.55556,0,0,5.55556,147.056,5192.61)">
<path d="M13.14,29.28C20.952,29.28 27.28,22.952 27.28,15.14L25.28,15.14C25.28,21.848 19.848,27.28 13.14,27.28L13.14,29.28ZM27.28,15.14C27.28,7.328 20.952,1 13.14,1L13.14,3C19.848,3 25.28,8.432 25.28,15.14L27.28,15.14ZM13.14,1C5.328,1 -1,7.328 -1,15.14L1,15.14C1,8.432 6.432,3 13.14,3L13.14,1ZM-1,15.14C-1,22.952 5.328,29.28 13.14,29.28L13.14,27.28C6.432,27.28 1,21.848 1,15.14L-1,15.14Z" style="fill:rgb(107,50,179);fill-rule:nonzero;"/>
</g>
<g transform="matrix(0,5.55556,5.55556,0,170.222,5276.72)">
<rect x="-8.97" y="7.97" width="17.94" height="2" style="fill:rgb(107,50,179);"/>
</g>
<g transform="matrix(-5.55556,0,0,5.55556,269.889,5265.61)">
<rect x="0" y="1" width="17.93" height="2" style="fill:rgb(107,50,179);"/>
</g>
</g>
</g>
</g>
</svg>
</button>
<?php endif ?>
<?php if ($field == 'longtext'): ?></div><?php endif ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php $this->endblock(); ?>
<?php if (count($articleItems)): ?>
<div class="related-articles-person">
<?php foreach ($articleItems as $article): ?>
<?php $this->block('item'); ?>
<div class="item article <?= $article['class'] ?>" id="article_<?= $article['raw']['id'] ?>" data-id="article_<?= $article['raw']['id'] ?>">
<?php foreach ($article['attributes'] as $field => $name): ?>
<?php if ((null !== ($value = $article[$this->getFormat()][$field] ?? null)) ||
(null !== ($value = $article['text'][$field] ?? null))): ?>
<div class="field <?= $field ?> <?php if ($field == 'longtext'): ?>modal<?php endif ?>">
<?php if ($field == 'longtext'): ?><div class="modal-inner"><?php endif ?>
<?php if (!$this->view->get('hideLabels')): ?>
<div class="label"><?= $translator->trans('field_label', ['%field_label%' => $name], 'metamodels_list') ?></div>
<?php endif; ?>
<?php if ($field == 'longtext'): ?>
<div class="modal-trigger-buttons">
<div class="modal-trigger-buttons_inner">
<button class="modal-close-button">
<svg width="100%" height="100%" viewBox="0 0 119 119" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;">
<g transform="matrix(1,0,0,1,-156,-1)">
<g id="close-button" transform="matrix(1,0,0,1,15.4793,-1693.22)">
<rect x="141" y="1695" width="117.833" height="117.833" style="fill:none;"/>
<g id="close" transform="matrix(3.79222,0,0,3.79222,137.457,1691.35)">
<g>
<g>
<path d="M16.47,32.036C7.905,32.036 0.962,25.08 0.962,16.5C0.962,7.92 7.905,0.964 16.47,0.964C25.035,0.964 31.979,7.92 31.979,16.5C31.979,25.08 25.035,32.036 16.47,32.036ZM16.47,30.036C23.932,30.036 29.979,23.975 29.979,16.5C29.979,9.025 23.932,2.964 16.47,2.964C9.009,2.964 2.962,9.025 2.962,16.5C2.962,23.975 9.009,30.036 16.47,30.036Z" style="fill:rgb(107,50,179);"/>
</g>
</g>
<path d="M8.986,9.002L23.955,23.998" style="fill:none;fill-rule:nonzero;stroke:rgb(107,50,179);stroke-width:2px;"/>
<path d="M23.955,9.002L8.986,23.998" style="fill:none;fill-rule:nonzero;stroke:rgb(107,50,179);stroke-width:2px;"/>
</g>
</g>
</g>
</svg>
</button>
<button class="modal-prev-button">
<svg width="100%" height="100%" viewBox="0 0 119 118" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;">
<g transform="matrix(1,0,0,1,-305,0)">
<g id="prev-button" transform="matrix(1,0,0,1,164.676,-1695)">
<rect x="141" y="1695" width="117.833" height="117.833" style="fill:none;"/>
<g id="preview" transform="matrix(3.79222,0,0,3.79222,-39.3413,1691.35)">
<g>
<g>
<path d="M63.092,32.036C54.529,32.036 47.583,25.078 47.583,16.5C47.583,7.922 54.529,0.964 63.092,0.964C71.654,0.964 78.6,7.922 78.6,16.5C78.6,25.078 71.654,32.036 63.092,32.036ZM63.092,30.036C70.551,30.036 76.6,23.972 76.6,16.5C76.6,9.028 70.551,2.964 63.092,2.964C55.633,2.964 49.583,9.028 49.583,16.5C49.583,23.972 55.633,30.036 63.092,30.036Z" style="fill:rgb(107,50,179);"/>
</g>
</g>
<path d="M66.95,8.51L59.436,16.259L66.95,24.085" style="fill:none;fill-rule:nonzero;stroke:rgb(107,50,179);stroke-width:2px;"/>
</g>
</g>
</g>
</svg>
</button>
<button class="modal-next-button">
<svg width="100%" height="100%" viewBox="0 0 119 119" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;">
<g transform="matrix(1,0,0,1,-452,-2)">
<g id="next-button" transform="matrix(1,0,0,1,311.769,-1692.43)">
<rect x="141" y="1695" width="117.833" height="117.833" style="fill:none;"/>
<g id="next" transform="matrix(3.79222,0,0,3.79222,-211.652,1691.35)">
<g>
<g>
<path d="M108.53,32.036C99.967,32.036 93.021,25.078 93.021,16.5C93.021,7.922 99.958,0.964 108.53,0.964C117.102,0.964 124.038,7.922 124.038,16.5C124.038,25.078 117.092,32.036 108.53,32.036ZM108.53,30.036C115.989,30.036 122.038,23.972 122.038,16.5C122.038,9.028 115.998,2.964 108.53,2.964C101.062,2.964 95.021,9.028 95.021,16.5C95.021,23.973 101.071,30.036 108.53,30.036Z" style="fill:rgb(107,50,179);"/>
</g>
</g>
<path d="M104.681,8.51L112.195,16.259L104.681,24.085" style="fill:none;fill-rule:nonzero;stroke:rgb(107,50,179);stroke-width:2px;"/>
</g>
</g>
</g>
</svg>
</button>
</div>
</div>
<?php endif; ?>
<?= $value ?>
<?php if ($field == 'intro'): ?>
<button class="button modal-trigger">
<svg width="100%" height="100%" viewBox="0 0 118 118" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<g id="button-trigger" transform="matrix(1,0,0,1,-141,-1695)">
<rect x="141" y="1695" width="117.833" height="117.833" style="fill:none;"/>
<clipPath id="_clip1">
<rect x="141" y="1695" width="117.833" height="117.833"/>
</clipPath>
<g clip-path="url(#_clip1)">
<g id="trigger-button1" serif:id="button-trigger" transform="matrix(0.75,0,0,0.75,34.8749,-2203.63)">
<g transform="matrix(5.55556,0,0,5.55556,147.056,5192.61)">
<path d="M13.14,29.28C20.952,29.28 27.28,22.952 27.28,15.14L25.28,15.14C25.28,21.848 19.848,27.28 13.14,27.28L13.14,29.28ZM27.28,15.14C27.28,7.328 20.952,1 13.14,1L13.14,3C19.848,3 25.28,8.432 25.28,15.14L27.28,15.14ZM13.14,1C5.328,1 -1,7.328 -1,15.14L1,15.14C1,8.432 6.432,3 13.14,3L13.14,1ZM-1,15.14C-1,22.952 5.328,29.28 13.14,29.28L13.14,27.28C6.432,27.28 1,21.848 1,15.14L-1,15.14Z" style="fill:rgb(107,50,179);fill-rule:nonzero;"/>
</g>
<g transform="matrix(0,5.55556,5.55556,0,170.222,5276.72)">
<rect x="-8.97" y="7.97" width="17.94" height="2" style="fill:rgb(107,50,179);"/>
</g>
<g transform="matrix(-5.55556,0,0,5.55556,269.889,5265.61)">
<rect x="0" y="1" width="17.93" height="2" style="fill:rgb(107,50,179);"/>
</g>
</g>
</g>
</g>
</svg>
</button>
<?php endif ?>
<?php if ($field == 'longtext'): ?></div><?php endif ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php $this->endblock(); ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php else: ?>
<?php $this->block('noItem'); ?>
<p class="info"><?= $this->noItemsMsg ?></p>
<?php $this->endblock(); ?>
<?php endif; ?>