ToUrl() is giving me a partial URL?

Hello there. I’m very new to Kirby and I love it so far. I’m running into an issue that maybe someone can help me with. The bottom line is that I’m trying to get the full URL of an image I’ve set in the blueprint.

Here’s an excerpt of the blueprint I’m using

    type: textarea
    size: huge
    type: files
    label: Exposition
    empty: "No image selected"

Here’s an excerpt from the template:

<?php  if ($page->cover()->exists()): ?>
<div class="exposition" style="background-image: url('<?= $page->cover()->toUrl() ?>');"></div>
<?php  endif ?>

However, instead of giving me the full url of the image in place, it gives me the base url and then the filename with nothing in between. Specifically:

http://xxx.xxxx.xx.xx/- 1 .jpg”

where the filename is 1.jpg

on a different page with a different image instead it responds with this:

http://xxx.xxxx.xx.xx/- > 16a25180-2215-4254-a4f2-7317a4983ea7 .jpeg

also of note: <?= $page->cover()->toFile() ?> works just fine as it creates an image tag in html.

Any thoughts on this? Maybe I’m not understanding how toUrl is supposed to work?

The object created with ->toFile() also has the full url:

<?php if($cover = $page->cover()->toFile()): ?>
<div class="exposition" style="background-image: url('<?= $cover->url() ?>');"></div>
<?php  endif ?>

I’d also suggest adding multiple: false to your files field.

1 Like

This worked wonderfully. Thank you!