Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-16T22:32:50.250Z
Answers.LastActivityDate: 2014-12-16T22:32:50.250Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-16T16:44:23.323Z
Answers.Text: 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
Answers.UserDisplayName: Steven Vandemoortele
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-16T16:48:36.047Z
Answers.Text: 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.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-16T16:57:31.110Z
Answers.Text: 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.
Answers.UserDisplayName: Steven Vandemoortele
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-16T16:39:01.010Z
Answers.LastActivityDate: 2014-12-16T17:23:13.550Z
Answers.LastEditDate: 2014-12-16T17:23:13.550Z
Answers.UserDisplayName: Douglas McDonald
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-12-16T16:21:57.280Z
Comments.Text: 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.
Comments.UserDisplayName: Ben Croker
Tags: <entries><slug><singles><templating>
Title: Get content of single by slug
ThreadText: # 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.  
  
  ---
  
  