# Using custom route and template to create user profile page

**URL:** <https://forum.getkirby.com/t/using-custom-route-and-template-to-create-user-profile-page/8644>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 28, 2017, 12:36pm UTC](https://forum.getkirby.com/t/using-custom-route-and-template-to-create-user-profile-page/8644 "2017-09-28T12:36:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![guillaumelobet](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/guillaumelobet/32/4642_2.png) [@guillaumelobet](https://forum.getkirby.com/u/guillaumelobet)\
**Post date:** [September 28, 2017, 12:36pm UTC](https://forum.getkirby.com/t/using-custom-route-and-template-to-create-user-profile-page/8644/1 "2017-09-28T12:36:53Z")

</div>

Hi

I am trying to create a custom profile page to display for each my website users.

I am trying to use a route to a custom template, but something seems to be buggy.

My router is:

```
c::set('routes', array(
  array(
    'pattern' => 'user/(:any)',
    'action' => function($usid) {
      // do something here when the URL matches the pattern above
    	return tpl::load(kirby()->roots()->templates() . DS . 'user.php', array('usid' => $usid), false);

    }
  )
));

```

Bu then, within the `user.php` file, when I try to call the `$site` object, nothing happens… so this:

`<? echo $site->url(); ?>`

will not return anything… However, this:

`<? echo $usid ?>`

does return the correct value passed by the router.

I am doing something wrong here?

---

<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:** [September 28, 2017, 12:40pm UTC](https://forum.getkirby.com/t/using-custom-route-and-template-to-create-user-profile-page/8644/2 "2017-09-28T12:40:28Z")

</div>

The problem is that when you load a template via a route, you have to define your variables in the router and pass them to the template.

```auto
$kirby = kirby();
$site = $kirby->site();
return tpl::load(kirby()->roots()->templates() . DS . 'user.php', array('site' => $site, 'usid' => $usid), false);

```

---

<div class="post-metadata">

**Author:** ![guillaumelobet](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/guillaumelobet/32/4642_2.png) [@guillaumelobet](https://forum.getkirby.com/u/guillaumelobet)\
**Post date:** [September 28, 2017, 1:06pm UTC](https://forum.getkirby.com/t/using-custom-route-and-template-to-create-user-profile-page/8644/3 "2017-09-28T13:06:19Z")

</div>

Great, thanks it works!

---

<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:27pm UTC](https://forum.getkirby.com/t/using-custom-route-and-template-to-create-user-profile-page/8644/5 "2025-02-06T17:27:58Z")

</div>

Archived on February 6, 2025, 5:27pm UTC


