Answers.Body: <p>You need to add <code>.first()</code> when setting the category. As far as I can tell, if you don't have <code>.first()</code> only <code>{{ category.slug }}</code> will work.</p>
  
  <p>First get the slug:
  </p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set catSlug = craft.request.getSegment(3) %}
  </code></pre>
  
  <p>This will give you the <a href="http://buildwithcraft.com/docs/templating/categorymodel">CategoryModel</a> object for catSlug:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set category = craft.categories.slug(catSlug).first() %}
  </code></pre>
  
  <p>You can now access whatever you want from the category, like the title:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{{ category.title }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-30T11:36:34.367Z
Answers.Text: You can’t pass in a string (`catSlug`) to `craft.categories()` – that `.slug(` is required to tell Craft that what you’re passing in is the slug, as opposed to an ID, etc.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-30T18:36:01.177Z
Answers.Text: @Brandon Required as in it won't work without it or as in you really should use it? This code worked for me, maybe my test wasn't in a clean enough environment.
Answers.UserDisplayName: Simon Kuran
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-30T22:08:55.863Z
Answers.Text: Required as in there’s no way it will work that way, and if it appeared to work, you probably just got lucky with the desired category happening to be the first one in the group.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-30T23:01:42.827Z
Answers.Text: @Brandon You got it, I did get lucky. :) I edited my answer, the lack of `.first()` is what was giving @brunam problems.
Answers.UserDisplayName: Simon Kuran
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-30T23:45:25.333Z
Answers.Text: Ah good catch! That explains why `category.slug` was working but `category.title` wasn’t – it was just returning the parameter value, rather than an actual category’s slug.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-29T23:43:59.747Z
Answers.LastActivityDate: 2014-07-30T23:03:01.710Z
Answers.LastEditDate: 2014-07-30T23:03:01.710Z
Answers.UserDisplayName: Simon Kuran
Body: <p>I'm setting my categories by matching the third segment to a category slug. How do I get the category title?</p>
  
  <pre><code>{% set catSlug = craft.request.getSegment(3) %}
  {% set category = craft.categories.slug(catSlug) %}
  </code></pre>
  
  <p>{{ category.slug }} returns the slug, but {{ category.title }} returns nothing.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-30T11:39:11.220Z
Comments.Text: If `{{ category.slug }}` is giving you the slug, it sounds like you’ve got is actually working. Not sure why `{{ category.title }}` would not be working though. What does `{{ dump(category) }}` give you? (you’ll need to have [dev mode](http://buildwithcraft.com/docs/config-settings#devMode) enabled to use that `dump()` function.)
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-30T12:14:05.827Z
Comments.Text: Hmm looks right to me? Could be the category is disabled?
Comments.UserDisplayName: Keith Mancuso
Tags: <categories><slug><getsegment>
Title: Get category title by slug
ThreadText: # Get category title by slug
  
  (Asked by: username_0 on 2014-07-29)
  
  I'm setting my categories by matching the third segment to a category slug. How do I get the category title?
  
  ```
  {% set catSlug = craft.request.getSegment(3) %}
  {% set category = craft.categories.slug(catSlug) %}
  
  ```
  
  {{ category.slug }} returns the slug, but {{ category.title }} returns nothing.
  
  **Tags:** categories, slug, getsegment
  
  > **Comments:**
  > **username_1**: If `{{ category.slug }}` is giving you the slug, it sounds like you’ve got is actually working. Not sure why `{{ category.title }}` would not be working though. What does `{{ dump(category) }}` give you? (you’ll need to have [dev mode](http://buildwithcraft.com/docs/config-settings#devMode) enabled to use that `dump()` function.)  
  > **username_2**: Hmm looks right to me? Could be the category is disabled?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2014-07-29. Score: 24 | Accepted answer
  
  You need to add `.first()` when setting the category. As far as I can tell, if you don't have `.first()` only `{{ category.slug }}` will work.
  
  First get the slug:
  
  ```twig
  {% set catSlug = craft.request.getSegment(3) %}
  
  ```
  
  This will give you the [CategoryModel](http://buildwithcraft.com/docs/templating/categorymodel) object for catSlug:
  
  ```twig
  {% set category = craft.categories.slug(catSlug).first() %}
  
  ```
  
  You can now access whatever you want from the category, like the title:
  
  ```twig
  {{ category.title }}
  
  ```
  
  > **Comments:**
  > **username_1**: You can’t pass in a string (`catSlug`) to `craft.categories()` – that `.slug(` is required to tell Craft that what you’re passing in is the slug, as opposed to an ID, etc.  
  > **username_3**: @username_1 Required as in it won't work without it or as in you really should use it? This code worked for me, maybe my test wasn't in a clean enough environment.  
  > **username_1**: Required as in there’s no way it will work that way, and if it appeared to work, you probably just got lucky with the desired category happening to be the first one in the group.  
  > **username_3**: @username_1 You got it, I did get lucky. :) I edited my answer, the lack of `.first()` is what was giving @username_0 problems.  
  > **username_1**: Ah good catch! That explains why `category.slug` was working but `category.title` wasn’t – it was just returning the parameter value, rather than an actual category’s slug.  
  
  ---
  
  