Compare pages list to pages field


I am trying to work out the best way of comparing the content of a pages field and a collection of pages.

Below is my rough outline of what I am trying to achieve:

$userPages = $kirby->user()->progressDetails()->toPages(); 
$pages = $site->find('pages')->children();
foreach($pages as $page):

// Here I want to list all the pages in their normal order, but do something different with them if they also appear in the progressDetails pages field for the user

if ($userPages->hasPage()) {
  // do your special thing
} else {
  // do normal stuff

Thanks for the quick reply! I can’t get this to work, I am probably implementing it wrong.

I have this:

<?php foreach($pages as $page): ?>
  <?php if($userPages->has($page)): ?>
    The user has found <?= $page->title() ?>
  <?php else: ?>
    Not found <?= $page->title() ?>
  <?php endif ?>
<?php endforeach ?>

All the pages are coming up as Not found though - I have a few pages selected in the field.

Sorry, was too fast, I forgot to add the $page as argument :see_no_evil:

 <?php if($userPages->has($page)): ?>

No worries - that still isn’t working for me actually.

Ah fixed it - it needs to be has() rather than hasPage()

Thanks for the help @texnixe that pointed me in the right direction

1 Like

Haha, I shouldn’t do this while doing a workout, the method is called has() not hasPage()-