Show the data from a linked page within a structure

Hi there!

For a carousel I use a structure with a pages field and optional custom titles to override the data from the linked page. The blueprint looks like this:

        type: fields
            type: structure
                type: pages
                label: Slide
                empty: Select entry
                max: 1
                type: toggle
                label: Custom title
                type: text
                  customize: true
                label: Custom tagline
                type: text
                  customize: true

Resulting data for the carousel is like this:

    - page://0cYH6z6FmTysL98b
  customize: 'true'
  custom_title: Say hi to Eurydice
  custom_tagline: "As she's the new star"
    - page://GELeqTgIYX55apBc
  customize: 'false'
  custom_title: ""
  custom_tagline: ""

Then in the template I like to get the data from the linked page. I can get the url using toPages() to link the slide to its referenced page, but I’m not able to get the data from that page (like the title or img src).

      $slides = $page->carousel()->toStructure();
      foreach ($slides as $slide):
      $production = $slide->link()->toPages(); ?>
        <img src="<?= $production ?>" style="object-position: <?= $production->focusPercentageX(); ?>% <?= $production->focusPercentageY(); ?>%">
        <a href="<?= $production ?>"><?= $production ?></a>
        <?= $slide->custom_title()->html() ?>
        <?= $slide->custom_tagline()->html() ?>
      <?php endforeach ?>

If there’s someone helping me a hand I’m much obliged!

Use toPage() here, for a single page. Otherwise you get a collection you would have to loop through. And don’t forget an if statement to make sure you really have a page.

But then you also have to call the props of the page, this for example

does not make sense, because this is not an image url.

Ha! Thanks for correcting the toPages() to toPage(). This will certainly help me. There’s a lot of info in the docs, but its a relief that a question on the forum is anwered with lightning speed :slight_smile: