Answers.Body: <p>Got it:</p>
  
  <p>Had already set the slug variable to the first segment in _layout.twig thus overriding everything after. m(</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-14T18:48:18.057Z
Answers.LastActivityDate: 2014-08-14T18:48:18.057Z
Answers.UserDisplayName: Marcus Scheller
Body: <p>I am trying to get a certain segment of the url. For this i’m setting the slug as a variable which seems to be best practice:</p>
  
  <pre><code>{% set slug = craft.request.getSegment(2) %}
  </code></pre>
  
  <p>I am interested in the second segment which is <a href="http://example.com/projects/awesome-project" rel="nofollow">http://example.com/projects/awesome-project</a> where “awesome-project” is the desired part.</p>
  
  <p>I never had any problem with this method but in this case it <em>always</em> returns the first segment (projects), regardless of the passed argument. The site is localized.</p>
  
  <p>I have tried various things but am completely clueless, atm. This can be reproduced with every template.</p>
  
  <p>What could be the culprit?</p>
  
Tags: <slug><getsegment>
Title: Having trouble setting/getting slug
ThreadText: # Having trouble setting/getting slug
  
  (Asked by: username_0 on 2014-08-14)
  
  I am trying to get a certain segment of the url. For this i’m setting the slug as a variable which seems to be best practice:
  
  ```
  {% set slug = craft.request.getSegment(2) %}
  
  ```
  
  I am interested in the second segment which is <http://example.com/projects/awesome-project> where “awesome-project” is the desired part.
  
  I never had any problem with this method but in this case it *always* returns the first segment (projects), regardless of the passed argument. The site is localized.
  
  I have tried various things but am completely clueless, atm. This can be reproduced with every template.
  
  What could be the culprit?
  
  **Tags:** slug, getsegment
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2014-08-14. Score: 2
  
  Got it:
  
  Had already set the slug variable to the first segment in \_layout.twig thus overriding everything after. m(
  
  
  ---
  
  