<pre><code>{% set newsSlug = craft.entries().section('news').select('elements_sites.slug').one().slug ?? null %}
</code></pre>
<p><strong>news</strong> - handle your section news;</p>
<p><strong>select('elements_sites.slug')</strong> - for get only slug your section;</p>
<p><strong>?? null</strong> - in case if there is no such section;</p>

CC BY-SA 4.0
2020-09-12T18:07:19.590Z
Thanks, trying this on the section handle "articlesRelatedToArtist" returns "articles-related-to-artist", but the URI format is "artist-news/{slug}", so I actually need the query to return "artist-news"
Matthias
CC BY-SA 4.0
2020-10-03T14:36:44.450Z
I tried this query on the "news" section with slug 'news' but it returns the slug of the first news article.... I need it to return the 'news' slug, how do I do that?
Matthias
CC BY-SA 4.0
2020-09-12T13:11:03.900Z
2020-09-12T13:11:03.900Z
Pavel Pavlovich
<p>I want to be able to get the slug of my news section dynamically by searching for its handle.
Slugs tend to change during the development phase, but the handle doesn't. That's why I want to hard code the news handle in my template to refer to the news section from any other page.</p>
<p>How to do such a query?</p>

<sections>
Retrieve section slug by handle
# Retrieve section slug by handle

(Asked by: username_0 on 2020-09-11)

I want to be able to get the slug of my news section dynamically by searching for its handle.
Slugs tend to change during the development phase, but the handle doesn't. That's why I want to hard code the news handle in my template to refer to the news section from any other page.

How to do such a query?

**Tags:** sections


---

## 1 answers

### Answer by username_1 on 2020-09-12. Score: 2

{% set newsSlug = craft.entries().section('news').select('elements_sites.slug').one().slug ?? null %}

news - handle your section news;
select('elements_sites.slug') - for get only slug your section;
?? null - in case if there is no such section;

> **Comments:**
> **username_0**: Thanks, trying this on the section handle "articlesRelatedToArtist" returns "articles-related-to-artist", but the URI format is "artist-news/{slug}", so I actually need the query to return "artist-news"  
> **username_0**: I tried this query on the "news" section with slug 'news' but it returns the slug of the first news article.... I need it to return the 'news' slug, how do I do that?  

---

