<p>Singles have no need for slugs, which is why we don't expose them in the CP UI for a single.</p>

<p>They only have one in the database because they're technically entries, and entries need slugs. But it's only a concept meant for Channel and Structure entries.</p>

CC BY-SA 3.0
2014-12-16T22:32:50.250Z
2014-12-16T22:32:50.250Z
Brad Bell
<p>I don't think that either the single's uri or the handle is technically considered a slug per se, although in the case of singles craft likely interprets the handle as such. A more appropriate way to access a single would be by using its section handle.</p>

<p>(updated) </p>

<pre><code>{% if craft.request.getSegment(1) == "this-is-a-segment" %}
    {% set item = craft.entries.section('mySectionHandle').first() %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2014-12-16T16:44:23.323Z
Your code won't work. In my example the slug returned from getSegment(1) is "this-is-a-segment". The section name however is thisIsASegment
Steven Vandemoortele
CC BY-SA 3.0
2014-12-16T16:48:36.047Z
ah... your right, of course it did. If you want to do this I would suggest making sure that the uri that you are using also matches the single's handle. Either that or use a conditional to use the correct handle.
Douglas McDonald
CC BY-SA 3.0
2014-12-16T16:57:31.110Z
That's what the craft.entries.section() function is for. I expected the craft.entries.slug() funtion to behave differently, which it does when using it to get the content of a channel or structure entry.
Steven Vandemoortele
CC BY-SA 3.0
2014-12-16T16:39:01.010Z
2014-12-16T17:23:13.550Z
2014-12-16T17:23:13.550Z
Douglas McDonald
<p>I'm trying to get the content of a single using a slug from the url.
I'm using the following code:</p>

<pre><code>{% set item = craft.entries.slug(craft.request.getSegment(1)).first() %}
</code></pre>

<p>This doesn't work, returns null, if there is a dash in segment 1.</p>

<p>For example if I have the following url: <a href="http://craft.dev/this-is-a-segment/segment2" rel="nofollow">http://craft.dev/this-is-a-segment/segment2</a> 
And in craftcms I have a single with title "This is a segment" and url "this-is-a-segment"
I can't get the content of that single.</p>

<p>If I change the slug to camelcase it does work, but I was under the impression that slug and section handle were two different things...</p>

<p>Is this a bug or am I doing something wrong?</p>

CC BY-SA 3.0
2014-12-16T16:21:57.280Z
your code above should work provided your slug is the same as the first segment. have you double checked? if yes, and you're on the latest version of craft, then i would report it as a bug.
Ben Croker
<entries><slug><singles><templating>
Get content of single by slug
# Get content of single by slug

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

I'm trying to get the content of a single using a slug from the url.
I'm using the following code:
{% set item = craft.entries.slug(craft.request.getSegment(1)).first() %}

This doesn't work, returns null, if there is a dash in segment 1.
For example if I have the following url: http://craft.dev/this-is-a-segment/segment2 
And in craftcms I have a single with title "This is a segment" and url "this-is-a-segment"
I can't get the content of that single.
If I change the slug to camelcase it does work, but I was under the impression that slug and section handle were two different things...
Is this a bug or am I doing something wrong?

**Tags:** entries, slug, singles, templating

> **Comments:**
> **username_1**: your code above should work provided your slug is the same as the first segment. have you double checked? if yes, and you're on the latest version of craft, then i would report it as a bug.  

---

## 2 answers

### Answer by username_2 on 2014-12-16. Score: 2 | Accepted answer

Singles have no need for slugs, which is why we don't expose them in the CP UI for a single.

They only have one in the database because they're technically entries, and entries need slugs. But it's only a concept meant for Channel and Structure entries.


---

### Answer by username_3 on 2014-12-16. Score: 2

I don't think that either the single's uri or the handle is technically considered a slug per se, although in the case of singles craft likely interprets the handle as such. A more appropriate way to access a single would be by using its section handle.
(updated) 
{% if craft.request.getSegment(1) == "this-is-a-segment" %}
    {% set item = craft.entries.section('mySectionHandle').first() %}
{% endif %}

> **Comments:**
> **username_0**: Your code won't work. In my example the slug returned from getSegment(1) is "this-is-a-segment". The section name however is thisIsASegment  
> **username_3**: ah... your right, of course it did. If you want to do this I would suggest making sure that the uri that you are using also matches the single's handle. Either that or use a conditional to use the correct handle.  
> **username_0**: That's what the craft.entries.section() function is for. I expected the craft.entries.slug() funtion to behave differently, which it does when using it to get the content of a channel or structure entry.  

---

