Get fields from a Page select menu

How do get the fields from a page (incentives) after being selected from a Select Field.

Currently <?= $plot->incentives() ?> pulls the Inventive title though but I also want to display a ‘subheading’ from the Incentive page

Select Field Code:

incentives:
  label: Incentive Offer
  type: select
  width: 1/4
  options:
  type: query
  query: page.children.listed.template('incentive')
  text: "{{ page.title }}"
  value: "{{ page.slug }}"

Template:

<?php $plots = $page->plotdetail()->toStructure(); ?>
<?php foreach ($plots as $plot): ?>
  <tr>
<?= $plot->plotname() ?>
    <th scope="row"><?= $plot->plotno() ?></th>
    <td><a class="plot-link relative" href="<?= $plot->plotname('value') ?>"><?= $plot->plotname() ?></a></td>
    <td><?= $plot->bedrooms() ?></td>
    <td><?= $plot->price() ?></td>
    <td><a href="<?= $plot->incentives() ?>" class="external-link"><?= $plot->incentives() ?></a></td>
  </tr>
<?php endforeach ?>

Don’t know why you are just storing the slug, would make more sense to store the id.

if ($incentivePage = page('incentives/' . $plot->incentives()->value())) {
  // do stuff
}

Sorry, I dont understand this. :frowning:

I wish to use something link this:

<a href="** link to incentive page selected** "><?= $incentivePage->subheading() ?></a>

Can you show me a typical example of what I would use in the “do stuff” area? I don’t know how to use this or what its performing. Sorry I am a PHP beginner

In my example above, $incentivePage is the page object, where I put the //do stuff you then have access to all method of a page object, e.g.

$incentivePage->url();
$incentivePage->title();

I have tried this and its not returning anything:

 <?php if ($incentivePage = page('incentives/' . $plot->incentives()->value())) {
 $incentivePage->url();
 $incentivePage->title();
  }
?>

You have to echo the stuff, otherwise you won’t see any output.

 <?php if ($incentivePage = page('incentives/' . $plot->incentives()->value())) {
 echo $incentivePage->url();
 echo $incentivePage->title();
  }
?>

Still nothing :confused:

Oh, what exactly is stored in the incentives page in your content file?

And where in the file system hierarchy does the selected page live?

If I were you, I’d use a pages field instead of a select field which was made for the purpose of selecting pages.

Or store at least the id instead of just the slug.