Hey there,
hopefully there is someone who can clean up my code concerning matching pages-field entries to another page.
This is the Structure of the site.
- Home
- Program
— event a
— event b
— event c
— … - Movies
— movie a
— movie b
— movie c
— … - …
Part of Event Blueprint:
category:
label: Kategorie
type: radio
translate: false
required: true
width: 1/2
options:
single: Film
multiple: Filmblock
movie:
width: 1/2
label: Filme
empty: Film auswählen…
type: pages
multiple: false
translate: false
min: 1
query: site.index.filterBy("template", "in", ["movie"])
when:
category: single
movies:
width: 1/2
label: Filme
empty: Filme auswählen…
type: pages
translate: false
min: 2
query: site.index.filterBy("template", "in", ["movie"])
when:
category: multiple
Part of Movie Template (this is where I made waste code but it works).
I think via FilterBy the code could be cleaned…
<?php
// find eventspage
$EventsPage = $site->index()->findBy('intendedTemplate', 'schedule');
// fetch all events by date > now
$AllEvents = $EventsPage->children()->listed()->filterBy('eventdate', 'date >', 'now')->sortBy('eventdate', 'asc');
// fetch all events by date < now
$AllPastEvents = $EventsPage->children()->listed()->filterBy('eventdate', 'date <', 'now')->sortBy('eventdate', 'desc');
?>
<!-- start loop -->
<?php foreach($AllEvents as $Event): ?>
<!-- check the event has single movie -->
<?php if ($Event->category() == 'single'): $SingleMovie = $Event->movie()->toPage()->title(); ?>
<!-- here starts the CHAOS – check matchings -->
<?php if ($page->title()->value() === $SingleMovie->value()): ?>
<!-- all the output I want to display -->
<?php endif ?>
<?php elseif ($Event->category() == 'multiple'): ?>
<!-- CHAOS round2 – loop through pages-field -->
<?php foreach($Event->movies()->toPages() as $MultipleMovie): ?>
<!-- more CHAOS – check matchings round2 -->
<?php if ($page->title()->value() === $MultipleMovie->title()->value()):?>
<!-- all the output I want to display -->
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>
I’m a heathen, but if there is a code god, I’ll go straight to hell for what I wrote above… at least I think so…
Thank you in advance!
Martin