Answers.Body: <p>You'll need to override the BaseElementType's <a href="http://buildwithcraft.com/classreference/elementtypes/BaseElementType#routeRequestForMatchedElement-detail" rel="nofollow">routeRequestForMatchedElement method</a> in your element type class as follows:</p>
  
  <pre><code>public function routeRequestForMatchedElement(BaseElementModel $element)
  {
      return array(
          'action' =&gt; 'templates/render',
          'params' =&gt; array(
              'template' =&gt; '_page',
              'variables' =&gt; array(
                  'page' =&gt; $element
              )
          )
      );
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-11T19:40:06.490Z
Answers.Text: exactly what i was hoping for!  Thanks Ben!
Answers.UserDisplayName: Keith Mancuso
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-04T19:59:40.703Z
Answers.LastActivityDate: 2015-01-04T19:59:40.703Z
Answers.UserDisplayName: Ben Croker
Answers.Body: <p>You could always route that section through a template that routes based on entry type. Something like this:</p>
  
  <pre><code>{% set section = entry.section.handle|default %}
  {% set entryType = entry.type|default('default') %}
  {% extends [
    '_sections/' ~ section ~ '/' ~ entryType ~ '.twig',
    '_sections/' ~ section ~ '/default.twig',
    '/_layouts/default.twig'
  ] %}
  </code></pre>
  
  <p>This way it will <code>extends</code> any template matching that type, or fall back to defaults.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-04T20:00:32.973Z
Answers.Text: I think you misread the question Tim, it is in reference to element types and not entry types.
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-30T12:17:12.203Z
Answers.LastActivityDate: 2015-01-05T11:10:58.667Z
Answers.LastEditDate: 2015-01-05T11:10:58.667Z
Answers.UserDisplayName: Tim Kelty
Body: <p>So I'm working on a prototyping plugin that has its own element type for pages.  My hope was to have a single <code>_page.html</code> template and much like entries or categories be able to tell Craft to map the routes for all the elements URIs to that template?</p>
  
  <p>But not having much luck figuring out how to do that?  </p>
  
  <p>I have URIs saving with my elements but how do I note which template to load?</p>
  
  <p>I assume it has something to do with registering routes but I'm not exactly sure where to start?</p>
  
Tags: <plugin-development><routes>
Title: How to define template routes for a custom element type
ThreadText: # How to define template routes for a custom element type
  
  (Asked by: username_0 on 2014-12-29)
  
  So I'm working on a prototyping plugin that has its own element type for pages. My hope was to have a single `_page.html` template and much like entries or categories be able to tell Craft to map the routes for all the elements URIs to that template?
  
  But not having much luck figuring out how to do that?
  
  I have URIs saving with my elements but how do I note which template to load?
  
  I assume it has something to do with registering routes but I'm not exactly sure where to start?
  
  **Tags:** plugin-development, routes
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-01-04. Score: 4 | Accepted answer
  
  You'll need to override the BaseElementType's [routeRequestForMatchedElement method](http://buildwithcraft.com/classreference/elementtypes/BaseElementType#routeRequestForMatchedElement-detail) in your element type class as follows:
  
  ```
  public function routeRequestForMatchedElement(BaseElementModel $element)
  {
      return array(
          'action' => 'templates/render',
          'params' => array(
              'template' => '_page',
              'variables' => array(
                  'page' => $element
              )
          )
      );
  }
  
  ```
  
  > **Comments:**
  > **username_0**: exactly what i was hoping for!  Thanks Ben!  
  
  ---
  
  ### Answer by username_2 on 2014-12-30. Score: 0
  
  You could always route that section through a template that routes based on entry type. Something like this:
  
  ```
  {% set section = entry.section.handle|default %}
  {% set entryType = entry.type|default('default') %}
  {% extends [
    '_sections/' ~ section ~ '/' ~ entryType ~ '.twig',
    '_sections/' ~ section ~ '/default.twig',
    '/_layouts/default.twig'
  ] %}
  
  ```
  
  This way it will `extends` any template matching that type, or fall back to defaults.
  
  > **Comments:**
  > **username_1**: I think you misread the question Tim, it is in reference to element types and not entry types.  
  
  ---
  
  