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:

carousel:
        type: fields
        fields:
          carousel:
            type: structure
            fields:
              link:
                type: pages
                label: Slide
                empty: Select entry
                max: 1
              customize:
                type: toggle
              custom_title:
                label: Custom title
                type: text
                when:
                  customize: true
              custom_tagline:
                label: Custom tagline
                type: text
                when:
                  customize: true

Resulting data for the carousel is like this:

- 
  link:
    - page://0cYH6z6FmTysL98b
  customize: 'true'
  custom_title: Say hi to Eurydice
  custom_tagline: "As she's the new star"
- 
  link:
    - 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).

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

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: