How to output raw file URL in a template?

I created a tab in my panel for files. Works great. Uploaded a logo.

I then created a file input in the main site.yml file for use on my home page. Selected my desired file (a logo). I want to pull the raw file URL into my template.

I was able to generate a proper image object in HTML, which includes the full URL and displays as you would expect an image to display, using the following: <?= $site->logo()->toFile() ?>

But when I use any of the methods I’m finding to print the raw URL, it only spits out the file name. in this case “- logo.svg” in plain text.

This is in my site blueprint:
image

When I use <?= $site->logo()->toFile() ?>:

When I use <?= $site->logo()->url() ?>
image

You have to convert the field value to a file object, then get the URL:

<?php if ($logo =  $site->logo()->toFile()): ?>
<?= $logo->url() ?>
<?php endif ?>

If you call the url() method on the field, you use the url() field method that just converts your field value into an URL.

1 Like

Thank you so much. Of course it worked perfectly. :smiley: I love you.

:joy: