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!