# Image()-\>url only coming up broken

**URL:** <https://forum.getkirby.com/t/image-url-only-coming-up-broken/15096>\
**Category:** Questions\
**Tags:** v3\
**Created:** [July 29, 2019, 10:28pm UTC](https://forum.getkirby.com/t/image-url-only-coming-up-broken/15096 "2019-07-29T22:28:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brighurst](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/brighurst/32/9714_2.png) [@Brighurst](https://forum.getkirby.com/u/Brighurst)\
**Post date:** [July 29, 2019, 10:28pm UTC](https://forum.getkirby.com/t/image-url-only-coming-up-broken/15096/1 "2019-07-29T22:28:17Z")

</div>

I’ve created this blueprint called amenities.yml:

```
title: Amenities

status:
  draft: true
  listed: true

options:
  url: false
  delete: false

fields:
  maintitle:
    label: Main Title
    type: text
    width: 1/2

  largetext:
    label: Text
    type: textarea
    width: 1/2

  leftimage:
    label: Left Image
    type: files
    query: page.images
    max: 1
    width: 1/2

  rightimage:
    label: Right Image
    type: files
    query: page.images
    max: 1
    width: 1/2

```

and I’ve linked it to a template called amenities.php like so:

```
<div class="columns">
  <div class="column">
   <div class="about-img"><img src="<?= $page->leftimage()->url() ?>"></div>

  </div>
  <div class="column">
  <div class="about-img"><img src="<?= $page->rightimage()->url() ?>"></div>
  </div>
</div>

```

However the image url comes up broken. When I inspect, it shows up as:  
`<img src="- 2_amenities_1.jpg">`

What’s going on?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 30, 2019, 6:35am UTC](https://forum.getkirby.com/t/image-url-only-coming-up-broken/15096/2 "2019-07-30T06:35:38Z")

</div>

If you call the `url()` method on a field, it just turns what is stored in the field into a Url (although you don’t get an Url, hm).

To get the Url of the image, you need to convert it to a file object first:

```auto
<?php if ($leftImage = $page->leftimage()->toFile()): ?>
   <div class="about-img"><img src="<?= $leftImage->url() ?>"></div>
<?php endif ?>

```

Same for the other image.

Within the if-statement we do three things at the same time:

- we convert the field value into a file object using the `toFile()` method
- we assign the result to a variable
- we check if what we assigned to the variable is an object or null/false

The if statement is necessary because we trust that what the reference we stored in the field is still pointing to a file (the file might have been deleted or renamed later).

---

<div class="post-metadata">

**Author:** ![Brighurst](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/brighurst/32/9714_2.png) [@Brighurst](https://forum.getkirby.com/u/Brighurst)\
**Post date:** [July 30, 2019, 2:25pm UTC](https://forum.getkirby.com/t/image-url-only-coming-up-broken/15096/3 "2019-07-30T14:25:23Z")

</div>

Now I’m getting an error “Function Name must be a string”

Also I used `url()` on a different template as is and it worked fine. For some reason, the images I upload are not being put into the `media folder`

When I use other templates, it seems to upload the file and display it just fine. I’m not sure what’s happening in this case.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 30, 2019, 2:35pm UTC](https://forum.getkirby.com/t/image-url-only-coming-up-broken/15096/4 "2019-07-30T14:35:45Z")

</div>

Sorry, when I modified your code I forgot to remove the parens. Corrected above.

> [@Brighurst](#):
>
> Also I used `url()` on a different template as is and it worked fine.

Well, that might have worked when the images are from the same page, but you wouldn’t be able to resize them etc. if you don’t create an object first. The code I posted above is the right way to go about this, not calling the `url()` field method .

See the documentation on how to use the files field in templates/snippets: [Files | Kirby CMS](https://getkirby.com/docs/reference/panel/fields/files#how-to-use-in-templates-snippets)
