Select field image get url

Hello,

I use the select field to set the favicon.

  favicon:
    label: Favicon
    type: files
    query: site.images
    multiple: false
    width: 1/2

<link rel="icon" type="image/png" href="<?php echo $site->favicon()->toFile() ?>">

output:

<link rel="icon" type="image/png" href="&lt;img alt=" "="" src="http://test.local/media/site/4170490690-1553845378/favicon.png">

I tried:

<link rel="icon" type="image/png" href="<?php echo $site->favicon()->url() ?>">

output:

<link rel="icon" type="image/png" href="- favicon.png">

how to get the url without the image tag ?

greetings john

<?php echo $site->favicon()->toFile()->url() ?>

But you shouldn’t use it like this, but

<?php if($favicon = $site->favicon()->toFile()): ?>
  <link rel="icon" type="image/png" href="<?= $favicon->url() ?>">
<?php endif ?>
1 Like

Thank you @texnixe

is

if($favicon = $site->favicon()->toFile())
the same
if($site->favicon()->toFile() != “”)

?

returns either a file object or false.

Also, it makes more sense to store the value in a variable that you can then use in the next line, something you can’t do otherwise.