I want to check if there is a tag equal to another output. This works well.
If the tag is equal I want to output more informations from the page the tag is coming from.
I don’t find any way to figure out the right code… ;I
<?php foreach($tags as $tag): ?>
<?php if($tag == $event_ort): ?>
<?php echo $tag ?>
// this is the place i would output the page-title and other fields from page
// <?php echo $my_content = $tag->… ?>
<?php endif ?>
<?php endforeach ?>
Like last times I hope you can give me a hint.
Regards
Martin
Yes, but from which page? Your tags seem to come from all over the place, i.e. $site->index(). If you pluck the unique tags from all these pages, you get a simple array of tags that are devoid of any information about the page you plucked them from.
<?php $events = page('programm/filme')->grandchildren()->visible(); ?>
// get all events
<?php foreach ($events->sortBy('ort_sreening', 'asc')->pluck('ort_sreening', null, true) as $event_ort): ?>
// output all location
<h1><?= $event_ort ?></h1>
<?php foreach($tags as $tag): ?>
<?php if($tag == $event_ort): ?>
<?php echo $tag ?>
// this is the place i would output the page-title and other fields from page
// <?php echo $my_content = $tag->… ?>
<?php endif ?>
<?php endforeach ?>
<?php foreach($events->filterBy('ort_sreening', $event_ort->toString())->sortBy('date', 'asc') as $event) : ?>
<?php $movie = $event->parent() ?>
// output all movies by there equal location
Maybe the way is wrong with tags to get informations from locations page. But I don’t find any other way for myself.
I guess you mean the title etc, of each event in the $events collection?
I assume what you really want to achieve here is to group your events by location? In any case with your current approach it will not work at all, because neither your tags array nor your locations array have any connection with the page.
First of all, I’d use Kirby’s group function, then you have each event in the second loop, can find the location page from the value of the ort_screening field of the event and thus have access to everything that is stored in the location page.
<?php
$groupedEvents = $events->sortBy('ort_sreening', 'asc')->groupBy('ort_screening');
foreach ( $groupedEvents as $location => $events ) :
?>
<h1><?= $location ?></h1>
<?php foreach ( $events as $event ) : ?>
<?= $event->title() ?>
<?php if ( $location = $site->index()->filterBy('template', 'location')->findBy('title', $event->ort_screening()->value()) ) : ?>
<?= echo $location->title(); /* or whatever information you want to get from the location page*/ ?>
<?php endif ?>
<?php endforeach ?>
<?php endforeach ?>
Try to prevent searching the $site->index() by narrowing down the path to the locations.