Answers.Body: <p>You might check out the routing docs on <a href="http://buildwithcraft.com/docs/routing#accessing-subpatterns-in-your-templates" rel="nofollow">accessing subpatterns in your templates</a>.</p>
  
  <p>Here is the example given in the docs (which provides the variables 'year' and 'month' to the template that correspond to the matched uri segments — which would match `news/2015/02'): </p>
  
  <pre><code>'news/(?P&lt;year&gt;\d{4})/(?P&lt;month&gt;\d{2})' =&gt; 'news/_archive',
  </code></pre>
  
  <p>So I would presume you could do the same using your products (I'm terrible with regular expression though, so please check the match syntax).</p>
  
  <pre><code>'products/(?P&lt;slug&gt;[^/]+)/details' =&gt; 'products/_details',
  </code></pre>
  
  <p>Fyi, the variable is defined using <code>(?P&lt;name&gt;...)</code>, where '...' is the pattern to match. So in this case the variable 'slug' (or whatever you defined it as in your regex pattern) should now be available as a variable in your template, which you can use to retrieve the entry. </p>
  
  <pre><code>{% set entry = craft.entries.section('mySectionHandle').slug(slug).first() %}
  {% if entry %}
      {{ entry.title }}
      ...
  {% endif %}
  </code></pre>
  
  <p>When you create the link to that page you would naturally want to include the slug:</p>
  
  <pre><code>&lt;a href="products/{{ entry.slug }}/details"&gt;View details&lt;/a&gt;
  </code></pre>
  
  <p>Untested.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-18T17:55:32.737Z
Answers.Text: This worked! I guess it was easier than I first thought. The only thing I had to do different was `{% set entry = craft.entries.section('mySectionHandle').slug(slug).first() %}`
Answers.UserDisplayName: Chad W
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-18T18:56:04.567Z
Answers.Text: Great! Ya... I couldn't remember if using slug returned an ElementCriteriaModel or EntryModel. I should have warned you. Glad you got it working. I updated the answer.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-17T22:24:16.863Z
Answers.LastActivityDate: 2015-02-18T18:54:45.500Z
Answers.LastEditDate: 2015-02-18T18:54:45.500Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>Suppose I have a section for Products, that uses the template at products/_entry and is set up to have the URL format of 'products/{slug}'.</p>
  
  <p>Our existing page structure shows a Product page when you go to the URL (such as <code>example.com/products/cool_product</code>, but we also have a sub-page for "Product Details" which we would get to (using the previous example) by going to <code>example.com/products/cool_product/details</code>.</p>
  
  <p>Is something like this possible with Craft routes? I've tried adding a route in <code>craft/config/routes.php</code> that looks like:</p>
  
  <pre><code>return array(
      'products/&lt;slug&gt;/details' =&gt; 'products/_details'
  );
  </code></pre>
  
  <p>however that doesn't do what I'd expect, which is load the product entry using that slug and display the template (which would in turn display the relevant data from that product entry)</p>
  
  <p>Do I need to have something in my <code>_layout.html</code> that catches such a request somehow? I'm a bit confused I guess. I suppose I can handle the request a bit more manually in the template by parsing the request and loading the product that way. I guess I'm hoping there is something a little more elegant (read: I'm lazy )</p>
  
Tags: <templating><routes><routing>
Title: "Subtemplates" for entry using routing?
ThreadText: # "Subtemplates" for entry using routing?
  
  (Asked by: username_0 on 2015-02-17)
  
  Suppose I have a section for Products, that uses the template at products/\_entry and is set up to have the URL format of 'products/{slug}'.
  
  Our existing page structure shows a Product page when you go to the URL (such as `example.com/products/cool_product`, but we also have a sub-page for "Product Details" which we would get to (using the previous example) by going to `example.com/products/cool_product/details`.
  
  Is something like this possible with Craft routes? I've tried adding a route in `craft/config/routes.php` that looks like:
  
  ```
  return array(
      'products/<slug>/details' => 'products/_details'
  );
  
  ```
  
  however that doesn't do what I'd expect, which is load the product entry using that slug and display the template (which would in turn display the relevant data from that product entry)
  
  Do I need to have something in my `_layout.html` that catches such a request somehow? I'm a bit confused I guess. I suppose I can handle the request a bit more manually in the template by parsing the request and loading the product that way. I guess I'm hoping there is something a little more elegant (read: I'm lazy )
  
  **Tags:** templating, routes, routing
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-02-17. Score: 6 | Accepted answer
  
  You might check out the routing docs on [accessing subpatterns in your templates](http://buildwithcraft.com/docs/routing#accessing-subpatterns-in-your-templates).
  
  Here is the example given in the docs (which provides the variables 'year' and 'month' to the template that correspond to the matched uri segments — which would match `news/2015/02'):
  
  ```
  'news/(?P<year>\d{4})/(?P<month>\d{2})' => 'news/_archive',
  
  ```
  
  So I would presume you could do the same using your products (I'm terrible with regular expression though, so please check the match syntax).
  
  ```
  'products/(?P<slug>[^/]+)/details' => 'products/_details',
  
  ```
  
  Fyi, the variable is defined using `(?P<name>...)`, where '...' is the pattern to match. So in this case the variable 'slug' (or whatever you defined it as in your regex pattern) should now be available as a variable in your template, which you can use to retrieve the entry.
  
  ```
  {% set entry = craft.entries.section('mySectionHandle').slug(slug).first() %}
  {% if entry %}
      {{ entry.title }}
      ...
  {% endif %}
  
  ```
  
  When you create the link to that page you would naturally want to include the slug:
  
  ```
  <a href="products/{{ entry.slug }}/details">View details</a>
  
  ```
  
  Untested.
  
  > **Comments:**
  > **username_0**: This worked! I guess it was easier than I first thought. The only thing I had to do different was `{% set entry = craft.entries.section('mySectionHandle').slug(slug).first() %}`  
  > **username_1**: Great! Ya... I couldn't remember if using slug returned an ElementCriteriaModel or EntryModel. I should have warned you. Glad you got it working. I updated the answer.  
  
  ---
  
  