Answers.Body: <p>You can get the parts of your URL using the <code>getSegment()</code> function. <a href="https://craftcms.com/docs/templating/craft.request#getSegment" rel="nofollow">https://craftcms.com/docs/templating/craft.request#getSegment</a></p>
  
  <p>Then use the <code>slug</code> parameter and the criteria model’s <code>first()</code> method to grab the entry. Global Sets are already preloaded, to access a set dynamically grab it from the <code>_context</code> variable.</p>
  
  <pre><code>{% set entryA = craft.entries.slug(craft.request.getSegment(1)).first() %}
  {% set entryB = craft.entries.slug(craft.request.getSegment(2)).first() %}
  {% set globalSet = _context[craft.request.getSegment(3)] ?? null %}
  
  {% if not entryA or not entryB or not globalSet %}
      {% exit 404 %}
  {% endif %}
  
  {{ entryA.title }} - {{ globalSet.myField }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-24T15:42:58.423Z
Answers.LastActivityDate: 2016-06-24T15:49:07.937Z
Answers.LastEditDate: 2016-06-24T15:49:07.937Z
Answers.UserDisplayName: carlcs
Body: <p>my url looks like this: </p>
  
  <pre><code>domain.tld/slug-1/slug-2/variable
  </code></pre>
  
  <p>And in Twig it shall look for an entry with the slug slug-1 and show it, then an entry with the slug slug-2 and show it and look up for a global where the name of the global is variable.</p>
  
  <p>How do I do this? I found:</p>
  
  <pre><code>{% set entry = craft.entries.section('section_handle').slug('my_slug') %}
  </code></pre>
  
  <p>But how do I tell Twig whats the first and whats the second slug? </p>
  
  <p>There are always 2 slugs and one variable.</p>
  
  <p>Thank you!</p>
  
Tags: <templating><slug>
Title: Twig: Show specific entry by url
ThreadText: # Twig: Show specific entry by url
  
  (Asked by: username_0 on 2016-06-24)
  
  my url looks like this:
  
  ```
  domain.tld/slug-1/slug-2/variable
  
  ```
  
  And in Twig it shall look for an entry with the slug slug-1 and show it, then an entry with the slug slug-2 and show it and look up for a global where the name of the global is variable.
  
  How do I do this? I found:
  
  ```
  {% set entry = craft.entries.section('section_handle').slug('my_slug') %}
  
  ```
  
  But how do I tell Twig whats the first and whats the second slug?
  
  There are always 2 slugs and one variable.
  
  Thank you!
  
  **Tags:** templating, slug
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-06-24. Score: 2 | Accepted answer
  
  You can get the parts of your URL using the `getSegment()` function. <https://craftcms.com/docs/templating/craft.request#getSegment>
  
  Then use the `slug` parameter and the criteria model’s `first()` method to grab the entry. Global Sets are already preloaded, to access a set dynamically grab it from the `_context` variable.
  
  ```
  {% set entryA = craft.entries.slug(craft.request.getSegment(1)).first() %}
  {% set entryB = craft.entries.slug(craft.request.getSegment(2)).first() %}
  {% set globalSet = _context[craft.request.getSegment(3)] ?? null %}
  
  {% if not entryA or not entryB or not globalSet %}
      {% exit 404 %}
  {% endif %}
  
  {{ entryA.title }} - {{ globalSet.myField }}
  
  ```
  
  
  ---
  
  