<p>Although the craft.users tag let you find users who have firstName or lastName matching whatever, I wouldn't try to match just against that, as you could end up having users with the same sames.</p>

<p>I would include the id of the user in the URL, so you would have something like example.com/user/1-first-last</p>

<p>Then you can lookup the profile by doing this:</p>

<ol>
<li>Add a <a href="http://buildwithcraft.com/docs/routing#dynamic-routes" rel="nofollow">dynamic route</a> that matches for example profile/(number)-*</li>
<li><p>Graf the profile with something like this:</p>

<pre><code>{# 
    - Use matches variable from dynamic route
    - matches.number will give you the expected id if you only have 
      one number segment in your dynamic route
#}
{% set userId = matches.number %}
{# Find user #}
{% if userId is defined %}
    {% set profile = craft.users.id(userId) | first %}
        {{ profile.name }}&lt;br/&gt;
        {{ profile.username }}&lt;br/&gt;
        {{ profile.email }}&lt;br/&gt;
        {{ profile.id }}&lt;br/&gt;
{% endif %}
</code></pre></li>
</ol>

CC BY-SA 4.0
2023-06-06T08:05:30.550Z
I accepted yours now.
Marcus Scheller
CC BY-SA 3.0
2014-09-16T14:53:40.413Z
“as you could end up having users with the same sames”

That’d definitely be an issue. Going with the id beforehand might be a good way to go. Thank you.
Marcus Scheller
CC BY-SA 3.0
2014-09-17T10:50:52.883Z
Good. In general, you want some kind of information that is sure to be unique to look up the user, like the id, username or e-mail.
Fred Carlsen
CC BY-SA 3.0
2014-12-20T19:00:55.217Z
@MarcusScheller Could you mark one of the answers as the accepted one?
Fred Carlsen
CC BY-SA 3.0
2014-12-22T21:26:50.373Z
We went with the username (identical names being an issue) so practically I haven’t further looked into any of the above.
Marcus Scheller
CC BY-SA 3.0
2014-09-16T14:47:57.287Z
2014-09-16T16:17:13.733Z
2014-09-16T16:17:13.733Z
Fred Carlsen
<p>Marcus, I think you can use <em>anything</em> as an url for a user's page. In your case, I'd make a <a href="http://buildwithcraft.com/docs/routing#dynamic-routes" rel="nofollow">dynamic route</a> like:</p>

<pre><code>user/*
</code></pre>

<p>and assign it a template, for instance:</p>

<pre><code>user/_entry
</code></pre>

<p>Within that template, all you'd have to do is lookup the user by the match found in the url. The variable <em>matches</em> contains the first-last part (the * part of your route). With that, the user should be easy to find:</p>

<pre><code>{% set names = matches[1] | split('-') %}
{% set user = craft.users.firstName(names[0]).lastName(names[1]).first() %}

{% if user %}
    // Do with it what you want
{% endif %}
</code></pre>

<p>You'd have to be careful, however, that no two identical first- and last name combinations exists. The advantage of using the username is that it's always unique.</p>

CC BY-SA 3.0
2014-09-16T14:56:38.487Z
Thanks Paul.

“two identical first- and last name combinations” -- True, so i might look into Fred’s suggestion using a combination of id and full name. Username would still be the fallback but just not preferred. At least i would not like that.
Marcus Scheller
CC BY-SA 3.0
2014-09-16T14:30:54.137Z
2014-09-16T14:30:54.137Z
Paul
<p>I like to have the user’s full name in their profile page-url rather than the username in case they don’t want their username associated with their full name. In my case they don’t get to set the username at the sign up point but might been asked for a username by the person signing them up.</p>

<p>So, how do i use the user’s full name as an identifier in the url of their profile page?</p>

<p>Like so: <code>example.com/user/first-last</code></p>

<p>Is that even possible?</p>

<url><user-profile>
Using a user’s full name in the URL
# Using a user’s full name in the URL

(Asked by: username_0 on 2014-09-16)

I like to have the user’s full name in their profile page-url rather than the username in case they don’t want their username associated with their full name. In my case they don’t get to set the username at the sign up point but might been asked for a username by the person signing them up.

So, how do i use the user’s full name as an identifier in the url of their profile page?

Like so: `example.com/user/first-last`

Is that even possible?

**Tags:** url, user-profile


---

## 2 answers

### Answer by username_1 on 2014-09-16. Score: 2 | Accepted answer

Although the craft.users tag let you find users who have firstName or lastName matching whatever, I wouldn't try to match just against that, as you could end up having users with the same sames.
I would include the id of the user in the URL, so you would have something like example.com/user/1-first-last
Then you can lookup the profile by doing this:

Add a dynamic route that matches for example profile/(number)-*
Graf the profile with something like this:
{# 
    - Use matches variable from dynamic route
    - matches.number will give you the expected id if you only have 
      one number segment in your dynamic route
#}
{% set userId = matches.number %}
{# Find user #}
{% if userId is defined %}
    {% set profile = craft.users.id(userId) | first %}
        {{ profile.name }}
        {{ profile.username }}
        {{ profile.email }}
        {{ profile.id }}
{% endif %}

> **Comments:**
> **username_0**: “as you could end up having users with the same sames”  That’d definitely be an issue. Going with the id beforehand might be a good way to go. Thank you.  
> **username_1**: Good. In general, you want some kind of information that is sure to be unique to look up the user, like the id, username or e-mail.  
> **username_1**: @MarcusScheller Could you mark one of the answers as the accepted one?  
> **username_0**: We went with the username (identical names being an issue) so practically I haven’t further looked into any of the above.  
> **username_0**: I accepted yours now.  

---

### Answer by username_2 on 2014-09-16. Score: 4

Marcus, I think you can use anything as an url for a user's page. In your case, I'd make a dynamic route like:
user/*

and assign it a template, for instance:
user/_entry

Within that template, all you'd have to do is lookup the user by the match found in the url. The variable matches contains the first-last part (the * part of your route). With that, the user should be easy to find:
{% set names = matches[1] | split('-') %}
{% set user = craft.users.firstName(names[0]).lastName(names[1]).first() %}

{% if user %}
    // Do with it what you want
{% endif %}

You'd have to be careful, however, that no two identical first- and last name combinations exists. The advantage of using the username is that it's always unique.

> **Comments:**
> **username_0**: Thanks username_2.  “two identical first- and last name combinations” -- True, so i might look into Fred’s suggestion using a combination of id and full name. Username would still be the fallback but just not preferred. At least i would not like that.  

---

