Answers.Body: <p>Currently, the conditional redirect is the best way. You can use it to load a template dynamically in the structure's generic _entry template using the include tag.</p>
  
  <p>My suggestion would be to add a lightswitch field that tells the entry to load a custom template. Then in the _entry template do something like this:</p>
  
  <pre><code>{% if entry.customTemplate %}
      {% include "section/_" ~ entry.slug %}
  {% else %}
      {% include "section/_generic" %}
  {% endif %}
  </code></pre>
  
  <p>This is the same basic idea used in Pixel &amp; Tonic's help page on <a href="http://buildwithcraft.com/help/entry-type-templates">using different templates for different entry types</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T20:02:04.880Z
Answers.Text: thanks bryan, this is close to what i did except that i managed to drop the conditional and use an array in the include in its place.
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T19:27:36.563Z
Answers.LastActivityDate: 2014-06-12T19:27:36.563Z
Answers.UserDisplayName: Bryan Redeagle
Answers.Body: <p>I think you are on the right track. Call the generic template <code>_route.html</code>, and have it do nothing but <code>{%extends ...%}</code> to route to the template you want.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T19:30:25.263Z
Answers.LastActivityDate: 2014-06-12T19:30:25.263Z
Answers.UserDisplayName: Marion Newlevant
Answers.Body: <p>The cleanest way I have found to achieve this is to create a generic template for the structure as well as a custom template for each entry that needs one, ensuring that its path matches the entry's uri. </p>
  
  <p>I then put this single line of code in the structure's selected template and it works beautifully:</p>
  
  <pre><code>{% extends [entry.uri, '_generic'] %}
  </code></pre>
  
  <p>This should work as well:</p>
  
  <pre><code>{% include [entry.uri, '_generic'] %}
  </code></pre>
  
  <p>If the entry's uri exists as a template route then it will be rendered, otherwise the generic template will be.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I recently extended this on a site to allow for unique custom pages, custom entry type pages and a fallback generic page:</p>
  
  <pre><code>{% extends [
      '_custom/' ~ entry.slug,
      '_entrytypes/' ~ entry.type,
      '_generic'
  ] %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-24T14:20:22.600Z
Answers.Text: If your entries are in Structure, and some pages need to use different template, you can use this code in your 'main' template defined in section settings. ``{% extends [
      craft.request.path,
      '_generic'
  ] %}``
Answers.UserDisplayName: Yuri Salimovskiy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-30T17:58:46.680Z
Answers.Text: Im having a bit of a problem managing this method where  the entry.uri file needs to extend blocks in the main file.  Any ideas?
Answers.UserDisplayName: Steve Adams
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-17T19:26:29.103Z
Answers.Text: no, not in the scenario above
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T19:46:03.940Z
Answers.Text: That's very clever! Per the Twig docs, "The first template that exists will be used as a parent".
  http://twig.sensiolabs.org/doc/tags/extends.html#dynamic-inheritance
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T20:23:15.837Z
Answers.Text: In my opinion, this should be marked as the best answer. You may also want to share this "recipe" on http://craftcookbook.net/
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T19:41:16.933Z
Answers.LastActivityDate: 2015-05-28T15:25:12.867Z
Answers.LastEditDate: 2015-05-28T15:25:12.867Z
Answers.UserDisplayName: Ben Croker
Body: <p>While setting up a site recently I wanted to route a specific entry in a structure section to its own custom template. Using a dynamic route sounded like the right option until I remembered that it wouldn't work due to Craft's routing order (matched entry uri comes before matched template). </p>
  
  <p>I considered adding a conditional redirect to the structure's generic template but this feels a bit dirty. Does anyone have a better solution of how to make this work?</p>
  
Tags: <templating><structure><custom><routing>
Title: How can I route a specific entry in a structure section to its own template?
ThreadText: # How can I route a specific entry in a structure section to its own template?
  
  (Asked by: username_0 on 2014-06-12)
  
  While setting up a site recently I wanted to route a specific entry in a structure section to its own custom template. Using a dynamic route sounded like the right option until I remembered that it wouldn't work due to Craft's routing order (matched entry uri comes before matched template).
  
  I considered adding a conditional redirect to the structure's generic template but this feels a bit dirty. Does anyone have a better solution of how to make this work?
  
  **Tags:** templating, structure, custom, routing
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2014-06-12. Score: 44 | Accepted answer
  
  The cleanest way I have found to achieve this is to create a generic template for the structure as well as a custom template for each entry that needs one, ensuring that its path matches the entry's uri.
  
  I then put this single line of code in the structure's selected template and it works beautifully:
  
  ```
  {% extends [entry.uri, '_generic'] %}
  
  ```
  
  This should work as well:
  
  ```
  {% include [entry.uri, '_generic'] %}
  
  ```
  
  If the entry's uri exists as a template route then it will be rendered, otherwise the generic template will be.
  
  **UPDATE:**
  
  I recently extended this on a site to allow for unique custom pages, custom entry type pages and a fallback generic page:
  
  ```
  {% extends [
      '_custom/' ~ entry.slug,
      '_entrytypes/' ~ entry.type,
      '_generic'
  ] %}
  
  ```
  
  > **Comments:**
  > **username_5**: That's very clever! Per the Twig docs, "The first template that exists will be used as a parent". http://twig.sensiolabs.org/doc/tags/extends.html#dynamic-inheritance  
  > **username_5**: In my opinion, this should be marked as the best answer. You may also want to share this "recipe" on http://craftcookbook.net/  
  > **username_4**: Im having a bit of a problem managing this method where  the entry.uri file needs to extend blocks in the main file.  Any ideas?  
  > **username_0**: no, not in the scenario above  
  > **username_3**: If your entries are in Structure, and some pages need to use different template, you can use this code in your 'main' template defined in section settings. ``{% extends [     craft.request.path,     '_generic' ] %}``  
  
  ---
  
  ### Answer by username_1 on 2014-06-12. Score: 5
  
  Currently, the conditional redirect is the best way. You can use it to load a template dynamically in the structure's generic \_entry template using the include tag.
  
  My suggestion would be to add a lightswitch field that tells the entry to load a custom template. Then in the \_entry template do something like this:
  
  ```
  {% if entry.customTemplate %}
      {% include "section/_" ~ entry.slug %}
  {% else %}
      {% include "section/_generic" %}
  {% endif %}
  
  ```
  
  This is the same basic idea used in Pixel & Tonic's help page on [using different templates for different entry types](http://buildwithcraft.com/help/entry-type-templates).
  
  > **Comments:**
  > **username_0**: thanks username_1, this is close to what i did except that i managed to drop the conditional and use an array in the include in its place.  
  
  ---
  
  ### Answer by username_2 on 2014-06-12. Score: 1
  
  I think you are on the right track. Call the generic template `_route.html`, and have it do nothing but `{%extends ...%}` to route to the template you want.
  
  
  ---
  
  