Get image selection from parent

Hey everyone :smile:

I have a little problem and need a hint to solve my problem.
I want to get the selected parent header-image to be the default selection in the children pages. If there is no other image selected on the children site kirby get the selection from the parent site.

<?php foreach($page->hero()->split(',') as $item): ?>
  <?php if($image = $page->image($item)): ?>
  <img src="<?php echo thumb($image, array('width' => 1010, 'height' => 200, 'crop' => true, 'quality' => 75), false) ?>" alt="<?php echo $page->title()->html() ?>">
<?php endif; ?>
<?php endforeach; ?>

Would be great to see some hints :smile:
Thank you!

Well, first of all, I guess you don’t really want your page title within the foreach loop or do you?

Other than that - supposing the above code is for the child page, you want to wrap an if - else statement around the above, that checks of $page->hero() is empty or not and if it is, then use the images from the parent page, sth. like.

  if($page->hero()->isNotEmpty()) {
    // put your code from above here
  } else {
     $images = $page->parent()->hero()->split(); //or whatever field you want to grab here
     foreach($images as $image) {
      // here goes your code

1 Like

Thank you for your response :smile:
And yes you are right, taking the page title is a dump idea… Although it would make sense in my case :smiley:

Great, that was exactly what I was looking for. Works perfect for me.
Thank You !!!