Related articles, show title in panel

I’m discovering the possibilities offered by Related articles. However, it seems as though when selecting related pages (which is actually just a structure field) in the panel, only the target pages’ uid is displayed (which makes sense, since it’s what’s actually stored in the field). How could I go about displaying the target’s title, or any other field linked to the target’s $page object?

Thanks a ton!

Do you mean the name displayed in the structure field in the panel? Im not entirely sure you can do that. If you look at the structure field docs, you display anything in there via the stuff wrapped in handlebars, but I don’t think there is a way to translate the UID into a title via the blue print - I think you would need to make a custom field for that.

If it was me, I would use a route to get a list of all the sites pages, and pump that into a select… then put that select into the structure field, so you can set multiple pages:

Here’s the route (I use the AutoID plugin since that gives you a fixed hook even if the UID changes, but you could probably tweak the below easily to just run off the UID instead):

  // Page Links
  array(
    'pattern' => 'pagelist.json',
    'action'  => function() {
      header('Content-type: application/json; charset=utf-8');
      // filter out some pages we don't want in the list by the templates they use
      $pages = site()->index()->visible()->filterBy('template', 'not in', ['error', 'blogarticle']);
      $json = array();

      foreach ($pages as $page) {
          $json[$page->autoid()->value()] = $page->title()->value();
      }

      echo json_encode($json);
    }
  ),

And put a select field like this inside your structure field:

relatedpagepicker:
  label:             Related Page Link
  type:              select
  options:           url
  help:              Related page to this page.
  url:               pagelist.json

I hope that helps. Alternatively you could use the related pages plugin, which works off tags rather then a manual list. You would need to tag up all your articles, so may not be feasible for what you need. However if you did do it, the related pages list would take care of itself because it lists pages with the same tags.

Check out the snippet field, it allows you to fine-tune what is displayed instead of the limited options of the entry.