Hi,
I would like to clean up the template below, but I don’t know how.
Can someone point me in the right direction?
I have a list of pages with a “related” select field in the panel that may point to another section (archive, in this case).
Inside the parent template, I need to know if the select field is filled, if the page exists and finally to access the data (url, title, …).
This is the home template:
<div class="carousel">
<?php foreach($page->children()->visible() as $item): ?>
<div class="carousel-cell">
<!-- ugly, help me -->
<?php
if($item->related()->isNotempty()) {
$relatedPage = $pages
->filterBy('template', 'archive')
->children()
->findBy('uid', $item->related());
if($relatedPage != null) {
$related = $relatedPage;
} else {
$related = false;
}
}
?>
<!-- ugly -->
<?php if($related): ?>
Things
<?php endif ?>">
</div><!-- carousel-cell -->
<?php endforeach ?>
</div><!--carousel -->
And this is the blueprint of home-item:
title: Home item
preview: parent
fields:
title:
label: Title
type: text
text:
label: Text
type: textarea
related:
label: Related
type: select
options: query
query:
page: archive
fetch: children
value: '{{uid}}'
text: '{{title}}'
Thank you!