Noob question: how can I access fields of a child page

Hi,

following the blog cookbook article which works perfectly and I am trying to add an image or self hosted video(MP4 only) to to any of the blog articles. I added the according field for image and video to the article YAML and want to read it from the parent page to display either the image or the video (or its poster) on top of each excerpt.

But I cant figure out how to access the according field entry. In the blog page I cycle through the entries
<?php foreach($page->children()->visible()->flip() as $entry): ?>

In the loop I try to read the fvideo (how I called it in the entries YAML)

<?php if($entry->$fvideo()->isNotEmpty()): ?>

and here it stops.The page and my understanding… :wink: Same for the image.
Any help appreciated. Many thanks in advance.

Remove that dollar :slight_smile:

<?php if($entry->fvideo()->isNotEmpty()): ?>

Should work

Many thanks!
I forgot to remove it … I added it experimentally because I did not get the full path to the file when I use it like
Guess this is the next noob question… I am new tp kirby and php
<?php echo $entry->fvideo()->url() ?>

this outputs: sitename->filename.mp4 with the correct filename but without the path to the file which should be
sitename->blog->entryname->filename.mp4

I think this should work:

<?php echo $entry->fvideo()->toFile()->url() ?>

For the image, it would be the same:

<?php foreach($page->children()->visible()->flip() as $entry): ?>
  <? if($image = $entry->image_fieldname()->toFile()): ?>
    <img src="<?= $image->url() ?>" alt="">
 <?php endif ?>
<?php endforeach ?>

In both cases, it makes more sense to check if the image exists, because even if the field name is not empty, the image/video might have been deleted. For example, if the field contains a value like “my_awesome_image.jpp” but the image does not exist, when calling the url() method on the non-existing image would otherwise result in an error.

1 Like

Many thanks again, works like a charm!