# Returning correct URL with URL

**URL:** <https://forum.getkirby.com/t/returning-correct-url-with-url/11357>\
**Category:** Questions\
**Tags:** v2\
**Created:** [October 1, 2018, 9:59am UTC](https://forum.getkirby.com/t/returning-correct-url-with-url/11357 "2018-10-01T09:59:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![denkstream](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/denkstream/32/6628_2.png) [@denkstream](https://forum.getkirby.com/u/denkstream)\
**Post date:** [October 1, 2018, 9:59am UTC](https://forum.getkirby.com/t/returning-correct-url-with-url/11357/1 "2018-10-01T09:59:10Z")

</div>

Hello everyone,

When I’m trying to retrieve link URL from a file from another subpage with this call

```auto
<?php 
$code = $data->codecall();
foreach($page->site()->index()->filterBy('receipe_code', '*=', $code) as $item): ?>
  <a href="<?= $item->receipe_file()->link() ?>">Herunterladen</a></li>
<?php endforeach ?>

```

I’m getting url to file in root - that’s not working because the file is another subpage.  
But when I’m using this:

```auto
 <li><?= $item->receipe_file()->link() ?></li>

```

I’m gettin correct link but there I cann’t place predefined Text for download like abowe. How can I fix this?

---

<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:** [October 1, 2018, 10:02am UTC](https://forum.getkirby.com/t/returning-correct-url-with-url/11357/2 "2018-10-01T10:02:28Z")

</div>

What is. stored in the `recipe_file` field?

---

<div class="post-metadata">

**Author:** ![denkstream](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/denkstream/32/6628_2.png) [@denkstream](https://forum.getkirby.com/u/denkstream)\
**Post date:** [October 1, 2018, 10:11am UTC](https://forum.getkirby.com/t/returning-correct-url-with-url/11357/3 "2018-10-01T10:11:19Z")

</div>

File name with extension. This is how it looks in blueprint:  
`
receipe_file:
label: Rezeptdatei
type: select
icon: file
options: query
query:
fetch: files
value: ‘{{filename}}’
text: ‘{{filename}}’
flip: true
`

and subpage txt

```
----
Odin-file: 135-018-d.docx
----
```

---

<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:** [October 1, 2018, 10:28am UTC](https://forum.getkirby.com/t/returning-correct-url-with-url/11357/4 "2018-10-01T10:28:55Z")

</div>

I have never used the link field method with a file. While this is probably fool proof, I would check if the file actually exists and only output a link if this is. the. case.

```auto
if($file = $item->receipe_file()->toFile()) {
  echo $file->url();
}

```

(Just on a side note because the spelling correction always kicks in, the word `receipe`doesn’t exist in English. Either `recipe` or `receipt`, depending on meaning)

---

<div class="post-metadata">

**Author:** ![denkstream](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/denkstream/32/6628_2.png) [@denkstream](https://forum.getkirby.com/u/denkstream)\
**Post date:** [October 1, 2018, 10:33am UTC](https://forum.getkirby.com/t/returning-correct-url-with-url/11357/5 "2018-10-01T10:33:11Z")

</div>

Thanks, that worked!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:26pm UTC](https://forum.getkirby.com/t/returning-correct-url-with-url/11357/6 "2025-02-06T17:26:05Z")

</div>


