Kirby Builder Question

Ok so for the last two hours, i’ve been trying to list stuff out on subpages with Kirby Builder to no avail. The example in the github repo works great on the actual page, but what i want to do is list out sub pages from a level above. I cant get this to work:

On page i have this to loop through the child pages and the loop through the builder fields on those pages

<?php foreach($page->children() as $workpost): ?>
  <?php foreach($workpost->builder()->toStructure() as $section): ?>
  <?php snippet('builder/' . $section->_fieldset(), array('data' => $section)) ?>
  <?php endforeach ?>
<?php endforeach ?>

My snippet looks like this…

<?php if ($data->picture()->isNotEmpty()): ?>
<section class="single-image">
  <?php echo $data->picture()->url() ?>
</section>
<?php endif ?>

However, the URL returned by this line:

<?php echo $data->picture()->url() ?>

Gives me this:

http://domain.dev/someimage.jpg

It looses its relationship to the page the image belongs to. How do i solve this and get a full and proper URL to the image?

It should have looked like this:

http://domain.dev/work/somework/someimage.jpg

Thanks.

The picture field only contains a filename, so it does not make sense to call the URL method on it to get the image URL, you have to turn that into an image object first.

<?php 
$image =  $data->picture()->toFile();
if($image) {
  echo $image->url();
}
?>
1 Like

Wowzers. Thanks, that’s been driving me nuts! Sorted.