Hi everyone, I am trying to get something to work, but got stuck here, so would appreciate any help!
I have an Intro page where I want to present selected projects pages, so I am using the ‘Checkboxes’ field to make a list selection. In my template I can get the checked options but I can’t get to the selected pages. Also ‘toPage()’ and other methods I’ve tried didn’t work.
$items = $site->find('intro')->pages_vids()->toPages(',');
if ($items->isNotEmpty()):
foreach ($items as $item): ?>
<h1><?= $item->title() ?></h1>
<?php endforeach ?>
<?php endif ?>
An additional if-statement that checks if the intro page exists is recommendable as well.
Why does your code not work?
<?php
// with the split method, you create an array of page id values
$items = $site->find('intro')->pages_vids()->split();
// you loop through that array, but `$item` is a simple string
foreach ($items as $item): ?>
<!-- here you try to convert this string into a page, this won't work,
because you can't call a page method (`toPage()`) on a string -->
<h1><?= $item->toPage()->title() ?></h1>
<?php endforeach ?>