# Using -\>url() on an image from another page not working

**URL:** <https://forum.getkirby.com/t/using-url-on-an-image-from-another-page-not-working/16910>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 17, 2020, 10:06pm UTC](https://forum.getkirby.com/t/using-url-on-an-image-from-another-page-not-working/16910 "2020-01-17T22:06:10Z")\
**Posts on this page:** 2\
**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:** [January 17, 2020, 10:06pm UTC](https://forum.getkirby.com/t/using-url-on-an-image-from-another-page-not-working/16910/1 "2020-01-17T22:06:10Z")

</div>

Hi there, I’m currently trying to call an image url from a subpage onto the homepage using the following code.

```
          <div <?php echo 'id="collapse'.$k.'"' ?> class="panel-collapse collapse" role="tabpanel" <?php echo 'aria-labelledby="heading'.$k.'"' ?>>
            <div class="panel-body">
            <?php foreach ($item->children() as $subitem): 
              $image = $subitem->preview()->toFiles();
              ?>
              <a class="sub-item" href="<?= $subitem->url() ?>">
              <?= $subitem->title()->kt() ?></a>
              <img src="<?= $subitem->preview()->url() ?>">
            <?php endforeach ?>
            </div>
          </div>
        </div> 

```

However doing so only outputs the file name as “—6.jpg” adding in a dash. How can I get this to work properly? and using $image-\>url() outputs nothing.

---

<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:** [January 17, 2020, 10:25pm UTC](https://forum.getkirby.com/t/using-url-on-an-image-from-another-page-not-working/16910/2 "2020-01-17T22:25:49Z")

</div>

> [@Brighurst](#):
>
> $image = $subitem-\>preview()-\>toFiles();

In this line you convert your preview field content into a files object (so on the right track) but then you are not using it but just calling the field content. Also, I assume you only have a single image, not multiple, so using `toFile()` is more suitable than `toFiles()`.

```auto
<?php foreach ($item->children() as $subitem): 
 <?php $image = $subitem->preview()->toFile(); ?>

 <a class="sub-item" href="<?= $subitem->url() ?>">
    <?= $subitem->title()->kt() ?></a>
    <?php if ($image): ?>
        <img src="<?= $image->url() ?>">
    <?php endif ?>
<?php endforeach ?>

```
