# GetPage from URL

**URL:** <https://discourse.gohugo.io/t/getpage-from-url/36978>\
**Category:** support\
**Created:** [February 4, 2022, 4:55pm UTC](https://discourse.gohugo.io/t/getpage-from-url/36978 "2022-02-04T16:55:18Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [February 4, 2022, 7:05pm UTC](https://discourse.gohugo.io/t/getpage-from-url/36978/9 "2022-02-04T19:05:10Z")

</div>

> [@Sid](#):
>
> ```auto
> ---
> title: New
> image: /images/new.jpg
> related_posts:
> - link: https://www.example.com/posts/nice-post/
> - link: https://www.example.com/posts/nice-post2/
> - link: https://www.example.com/life/nice-post3/
> ---
> 
> ```

This is fundamentally the wrong way to do it, for a number or reasons:

- The URL can can be affected by configuration (`permalinks`) and front matter (`slug`, `url`), but you’ve hardcoded the result.
- By the same token, there is not an efficient way to perform a reverse lookup from URL to `.File.Path`, which is what you need in order to `.GetPage`

Instead…

```yaml
---
title: Post 1
date: 2022-02-04T18:58:11.000Z
draft: false
related:
  - /post/post-2
  - /post/post-3
---

```

Then:

```auto
{{ with .Params.related }}
  {{ range . }}
    {{ with site.GetPage . }}
      <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
    {{ end }}
  {{ end }}
{{ end }}

```

---

_[View the full topic](https://discourse.gohugo.io/t/getpage-from-url/36978)._
