<p>For this a good approach is to use the excellent Dynamic Routing system in Craft.</p>

<h2>Solution #1</h2>

<p>First create your section "Artists":</p>

<p><img src="https://i.sstatic.net/ImtMa.png" alt="enter image description here"></p>

<p>After that go to "Settings" -> "Routes" and add this Dynamic Route:</p>

<p><img src="https://i.sstatic.net/SQz8g.png" alt="enter image description here"></p>

<p>When this is done all URL requests made to "/artists/-whatever-" will be routed to the "artists/_entry" template. Now you can create your link like this:</p>

<pre><code>&lt;a href="/artists/{{ entry.slug }}/{{ entry.firstNameField }}/{{ entry.lastNameField }}"&gt;Artist Name&lt;/a&gt;
</code></pre>

<p>Your URL might now look like this rendered:</p>

<pre><code>&lt;a href="/artists/ladygaga/firstname/lastname"&gt;Lady Gaga&lt;/a&gt;
</code></pre>

<p>In your "_entry" template you can now fetch your entry using this code:</p>

<pre><code>{% set entry = craft.entries.section('artists').slug(craft.request.getSegment(2)).first() %}
Artist Name: {{ entry.title }}
</code></pre>

<h2>Solution #2</h2>

<p>If you instead want the URL to be "/artists/firstname-slug" you can alter the Dynamic Route slightly and use the Twig filter "split" to get the slug from the URL.</p>

<p>First change the Dynamic Route to:</p>

<pre><code>artists/*
</code></pre>

<p>Then update your template "_entry" with the following code:</p>

<pre><code>{% set segments = craft.request.getSegment(2)|split('-') %}
{% set entry = craft.entries.section('pages').slug(segments[1]).first() %}
Title: {{ entry.title }}
</code></pre>

<p>Your URL can now be "/artists/{{ entry.firstNameField }}-{{ entry.slug }}" and the template code will take care of the rest.</p>

CC BY-SA 3.0
2014-08-12T20:11:15.107Z
Thanks! After after few adjustments, it finally works for me. But is there a way to get an URL like /firstname-lastname instead of /firstname/lastname? I tried some Routes with **-** instead of **/** but got 404 errors or wrong pages.
Romain P.
CC BY-SA 3.0
2014-08-12T20:19:43.047Z
Just make the route "/artists/*/*" instead and make the URL "/artists/slug/firstname-lastname" in your template. Will be the same result :)
naboovalley
CC BY-SA 3.0
2014-08-12T20:28:34.687Z
As explained in my request: lastname = slug. So I'm trying an url like this: /artists/firstname-slug (to get something like /artists/lady-gaga, where gaga is the title of my entry = the slug). Unfortunately that does not work like this.
Romain P.
CC BY-SA 3.0
2014-08-12T21:30:50.630Z
Please see my edited post @Romainpoirier on how to make a URL the way you want it. Please accept my answer if you feel it's the right one.
naboovalley
CC BY-SA 3.0
2014-08-13T06:46:43.687Z
Thank you very much for your clear explanations! Now it works perfectly for me! :-)
Romain P.
CC BY-SA 3.0
2014-08-15T14:38:27.190Z
Just one more question: how would you do to avoid _'%20'_ spaces in first segment if _artistFirstName_ is composed of more than one word? I already have an **| upper** filter, and tried to add **| join**, **| url_encode** or **| replace** filters but failed to find the correct solution.
Romain P.
CC BY-SA 3.0
2014-08-18T06:45:15.870Z
A "|replace" filter with " ", "-" should work. No?
naboovalley
CC BY-SA 3.0
2014-08-12T13:21:52.857Z
2014-08-12T21:27:29.103Z
2014-08-12T21:27:29.103Z
naboovalley
<p>I try to compose an entry URL for artists pages with first name and last name.</p>

<p>Now:</p>

<pre><code>artists/{slug} = artists/{{ entry.title }}
{slug} = {{ entry.title }} = Artist Last Name
</code></pre>

<p>What I want to add at the end of the URL (Plain Text field):</p>

<pre><code>{{ entry.artistFirstName }} = Artist First Name
</code></pre>

<p>What I try to get, but which is not working:</p>

<pre><code>artists/{slug}-{{ entry.artistFirstName }}
</code></pre>

<p>Is it possible? how? And how can I add a conditional to check if <em>entry.artistFirstName</em> is defined?</p>

<p>Thanks!</p>

CC BY-SA 3.0
2014-08-10T07:56:40.360Z
you could just have the URL in your template any way you like ("/template/slug/firstname/lastname") and then just use the {slug} when fetching the entry from the database. An idea.
naboovalley
CC BY-SA 3.0
2014-08-10T08:16:14.350Z
I don't know if I well understood, but I tried to add something like {% set slug = "/entry.artistFirstName/entry.title/" %} in the template requested to display this page but this didn't affect the URL.
Romain P.
CC BY-SA 3.0
2014-08-11T08:22:05.963Z
I was thinking you leave the URL setting as is in Craft (like "artists/{slug}" for example). Then when creating the links in Twig just make them "/artists/{slug}/{entry.artistFirstName}". In your template when just fetch the single entry using segment #2. Could that work for you?
naboovalley
CC BY-SA 3.0
2014-08-11T18:53:46.687Z
Thanks! I created a link like <a href="{{entry.artistFirstName}}-{{ entry.url }}"> that works, but of course the link points to a page that does not exist and generates an error 404. How can I just fetch the {{ entry.url }} segment and continuing to display the full URL I want?
Romain P.
<url><slug><entry>
Is it possible to add an entry value to the entry URL Format?
# Is it possible to add an entry value to the entry URL Format?

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

I try to compose an entry URL for artists pages with first name and last name.
Now:
artists/{slug} = artists/{{ entry.title }}
{slug} = {{ entry.title }} = Artist Last Name

What I want to add at the end of the URL (Plain Text field):
{{ entry.artistFirstName }} = Artist First Name

What I try to get, but which is not working:
artists/{slug}-{{ entry.artistFirstName }}

Is it possible? how? And how can I add a conditional to check if entry.artistFirstName is defined?
Thanks!

**Tags:** url, slug, entry
> **Comments:**
> **username_1**: you could just have the URL in your template any way you like ("/template/slug/firstname/lastname") and then just use the {slug} when fetching the entry from the database. An idea.  
> **username_0**: I don't know if I well understood, but I tried to add something like {% set slug = "/entry.artistFirstName/entry.title/" %} in the template requested to display this page but this didn't affect the URL.  
> **username_1**: I was thinking you leave the URL setting as is in Craft (like "artists/{slug}" for example). Then when creating the links in Twig just make them "/artists/{slug}/{entry.artistFirstName}". In your template when just fetch the single entry using segment #2. Could that work for you?  
> **username_0**: Thanks! I created a link like <a href="{{entry.artistFirstName}}-{{ entry.url }}"> that works, but of course the link points to a page that does not exist and generates an error 404. How can I just fetch the {{ entry.url }} segment and continuing to display the full URL I want?  

---

## 1 answers

### Answer by username_1 on 2014-08-12. Score: 5 | Accepted answer

For this a good approach is to use the excellent Dynamic Routing system in Craft.
Solution #1
First create your section "Artists":

After that go to "Settings" -> "Routes" and add this Dynamic Route:

When this is done all URL requests made to "/artists/-whatever-" will be routed to the "artists/_entry" template. Now you can create your link like this:
Artist Name

Your URL might now look like this rendered:
Lady Gaga

In your "_entry" template you can now fetch your entry using this code:
{% set entry = craft.entries.section('artists').slug(craft.request.getSegment(2)).first() %}
Artist Name: {{ entry.title }}

Solution #2
If you instead want the URL to be "/artists/firstname-slug" you can alter the Dynamic Route slightly and use the Twig filter "split" to get the slug from the URL.
First change the Dynamic Route to:
artists/*

Then update your template "_entry" with the following code:
{% set segments = craft.request.getSegment(2)|split('-') %}
{% set entry = craft.entries.section('pages').slug(segments[1]).first() %}
Title: {{ entry.title }}

Your URL can now be "/artists/{{ entry.firstNameField }}-{{ entry.slug }}" and the template code will take care of the rest.

> **Comments:**
> **username_0**: Thanks! After after few adjustments, it finally works for me. But is there a way to get an URL like /firstname-lastname instead of /firstname/lastname? I tried some Routes with **-** instead of **/** but got 404 errors or wrong pages.  
> **username_1**: Just make the route "/artists/*/*" instead and make the URL "/artists/slug/firstname-lastname" in your template. Will be the same result :)  
> **username_0**: As explained in my request: lastname = slug. So I'm trying an url like this: /artists/firstname-slug (to get something like /artists/lady-gaga, where gaga is the title of my entry = the slug). Unfortunately that does not work like this.  
> **username_1**: Please see my edited post @Romainpoirier on how to make a URL the way you want it. Please accept my answer if you feel it's the right one.  
> **username_0**: Thank you very much for your clear explanations! Now it works perfectly for me! :-)  
> **username_0**: Just one more question: how would you do to avoid _'%20'_ spaces in first segment if _artistFirstName_ is composed of more than one word? I already have an **| upper** filter, and tried to add **| join**, **| url_encode** or **| replace** filters but failed to find the correct solution.  
> **username_1**: A "|replace" filter with " ", "-" should work. No?  

---

