Error on url() call


I get an error when I click on a image that is linked to a page. What can I do?
This is the “home” template where I want to display and link some Teaser

This Error:

Method Kirby\Cms\Field::__toString() must not throw an exception, caught Whoops\Exception\ErrorException: Array to string conversion

<?php foreach(page('reiseangebote')->children()->limit(3) as $ang): ?>
            <div class="col-xs-12 col-lg-4 teaser_block space_bottom">
            <a href="<?php echo $ang->url()?>"><img class="t_img img-fluid" src="<?= $ang->image($ang->teaser_bild())->url() ?>"></a>  
            <div class="space_top3 space_bottom3"><?php echo $ang->tage()?> Tage</div>
            <a href="<?php echo $ang->url()?>"><h4><span class="dark"><?php echo $ang->title()?></span></h4></a>
            <div class="space_top3">
                <a href="<?php echo $ang->url()?>"><img src="<?php echo url('assets/images/mehr.svg') ?>"></a> 
             <?php endforeach ?>

Hm, I’d would guess the error is caused by this line:

<?= $ang->image($ang->teaser_bild())->url() ?>

But that doesn’t explain why the error occurs when clicking on the image.

Does your error have a stack trace in which line it is thrown?

I also get this info:

That screenshot doesn’t help, but it tells me that I’m probably right and it has to do with the image.

In any case, you should never ever use code like this without making sure you have an image.

<?php if($image = $ang->teaser_bild()->toFile()): ?>
<a href="<?php echo $ang->url()?>">
  <img class="t_img img-fluid" src="<?= $image->url() ?>">
<?php endif ?>

I deleted everything till this line:

<a href="<?php echo $ang->url()?>"><img src="<?php echo url('assets/images/mehr.svg') ?>"></a>

But still get the error when I click on the link

Ah, you get the error when you click on the mehr link? I thought you said when you click on the image?

But if the error when you click on the link, I would assume for the error to be caused in the target page.

Yes, its the same Link on the image and the button.
Something seems to be wrong with this code:

<?php echo $ang->url()?>"

Could you please post the complete error screen?

As you said its a problem on the landing page and just found out its not on every page the error so seems that a file or something is missing. Here is the screenshot:

I think its because the Teaser image seems to have a wrong name on the content page:


No idea where this comes from! In the admin panel its correct:

The filename looks identical to me?

Use ->toFile() to delete „- “.

1 Like

the indent was the problem or the line break. I duplicated another page and changed all the data.

The files field in Kirby 3 stores your values in yaml format, so deleting the dash and line break is not of much use. As I already mentioned in a post above, to fetch the file from the content file you have to use $page->fieldname()->toFile() for a single files or $page->fieldname()->toFiles() for multiple files.

1 Like

Thank you for the info.

One other question: Is there a way to store and change global variables?
For example I have a contact page with a dropdown (Selectbox) and I want
dynamically change the preselection of the dropdown. Is this possible?

You can use config options for this purpose.

But there is no way to set a dynamic default value in a blueprint, unless you create your custom version of the select field.

Sounds complicated. Just the value of the the select box is dynamic.
Just looking for something like this:

<?php foreach($angebote_list as $entry): ?>
...if (global_var ==  $entry->value()?) > selected  
<option value="<?php echo $entry->value()?>"><?php echo $entry->text()?></option>
<?php endforeach ?>

Oh, you are in the frontend, I though you were talking about the Panel.

In the frontend, you can set your value anywhere, in the config for example, then get it via the option() helper.

return [
  'someGlobalValue' => 'myvalue'


$globalValue = option('someGlobalValue');

Looking good. Is there a way to change the Var?

You mean change the value of the variable? No. Then that value would probably be better off in the site settings.