Answers.Body: <p>It sounds like you're wanting to move templates around like this:</p>
  
  <pre><code>articles/index.html
  articles/_entry.html
  </code></pre>
  
  <p>To this:</p>
  
  <pre><code>_layouts/articles/index.html
  _layouts/articles/entry.html
  </code></pre>
  
  <p>There are three basic ways Craft figures out what template to use based on the URL:</p>
  
  <ul>
  <li>Element routing like <code>articles/_entry.html</code> (matches a URI in an element's settings, e.g. section or category)</li>
  <li><a href="https://docs.craftcms.com/v3/routing.html#dynamic-routes" rel="nofollow noreferrer">dynamic routes</a> and <a href="https://docs.craftcms.com/v3/routing.html#dynamic-routes" rel="nofollow noreferrer">URL Rules</a></li>
  <li><a href="https://docs.craftcms.com/v3/dev/#template-paths" rel="nofollow noreferrer">Template path</a> routing like <code>articles/index.html</code></li>
  </ul>
  
  <p>(<a href="https://docs.craftcms.com/v3/routing.html" rel="nofollow noreferrer">Craft 3 docs on routing</a>)</p>
  
  <p>To get a URL like <code>http//example.com/articles</code> to use the template <code>_layouts/articles/index.html</code>, you have two options:</p>
  
  <ol>
  <li>Set up a dynamic route or URL rule.</li>
  <li>Create a Single with the URI set to <code>articles</code>.</li>
  </ol>
  
  <p>Personally, I often create a Single for this like a Blog index page. Then it's easy to control parts of the index page like a header image or custom SEO tags. </p>
  
  <p>A <strong>dynamic route</strong> would look like this:</p>
  
  <p><a href="https://i.sstatic.net/2ka4H.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2ka4H.png" alt="dynamic route example screenshot"></a></p>
  
  <p>A <strong>URL rules</strong> would work something like this in <code>config/routes.php</code>:</p>
  
  <pre><code>'articles' =&gt; ['template' =&gt; '_layouts/articles/index'],
  </code></pre>
  
  <p>A third option that I don't recommend is if you have a structured section called something like "Pages" (or Static Pages or Landing Pages), you could create different Entry Types called "Page" and "Articles Index" just for this. </p>
  
  <pre><code>├── About Us (Page)
  │   └── Our Team (Page)
  ├── Articles (Articles Index)
  ├── Services (Page)
  └── Contact (Page)
  </code></pre>
  
  <p>I'm not a fan of this for a few reasons, but the main one is that you can't point entry types to different templates in Craft so you'll probably have to use Twig includes to create a "routing template" that points the Article Index entry type to a different template. Also,  chances are you will never need more than one Articles index page, and you won't want to drag and drop it's location around the structure because the URLs will become out of sync with the child Article entries.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-14T07:28:35.333Z
Answers.Text: The problem solved itself when we realized we would need a single for each "index" page, just like your blog example. But it's good to know that the routes can be defined in the config.
Answers.UserDisplayName: dazz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-13T21:34:21.427Z
Answers.LastActivityDate: 2018-09-14T08:37:49.480Z
Answers.LastEditDate: 2018-09-14T08:37:49.480Z
Answers.UserDisplayName: Alex Roper
Answers.Body: <p>You can't create a url path that goes to a _*** folder.  If you rename your folder without the underscore, it should work.  Folders that uses underscores are kind of protected and can only be used by other templates.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-12T07:28:04.493Z
Answers.Text: Unless you tell your structure/channel/whatever to look at an underscored template explicitly then it will work.
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-11T15:11:54.617Z
Answers.LastActivityDate: 2018-09-11T15:11:54.617Z
Answers.UserDisplayName: Eric Chantigny
Answers.Body: <p>This is how my templates directory looks for almost every project:</p>
  
  <pre><code>Templates
  --- _layout
  --- includes
  --- partials
  --- site
  --- users
  --- shop
  </code></pre>
  
  <p>As long as your templates update their 'extend' tag to be <code>{% extends '_layout/base' %}</code> then Craft understands where that is. Craft is aware of everything in the templates directory, you don't need to set up much config except for things like the users login/password templates.</p>
  
  <p>My main site pages structure is setup in the CMS to look at <code>/site/_index.twig</code> then all the entry.types within this structure are based on this template and I include the entry type's appropriate template in my site base file.</p>
  
  <p>Let me know if you need more details.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-11T13:52:59.567Z
Answers.LastActivityDate: 2018-09-11T13:52:59.567Z
Answers.UserDisplayName: Jay
Body: <p>We want to add a little more structure to our templates directory by adding folders to group templates files.</p>
  
  <p>For example:</p>
  
  <pre><code>templates
  --_macros
  --_views
  --_layouts
  </code></pre>
  
  <p>In general this works fine but we encountered a problem with the index pages of sections.
  All pages are grouped in the views directory, so in views we could have a folder "articles" and within that a file "_entry.twig" and "index.twig".</p>
  
  <p>For the entry to work we change the template path of the section in the backend.
  But there is no place to this for the index file.</p>
  
  <p>Anybody an idea how best to handel this? 
  Is there a way to tell craft to also look in de _views folder?</p>
  
Tags: <templating><craft3><sections>
Title: Craft templates in sub directory
ThreadText: # Craft templates in sub directory
  
  (Asked by: username_0 on 2018-09-11)
  
  We want to add a little more structure to our templates directory by adding folders to group templates files.
  
  For example:
  
  ```
  templates
  --_macros
  --_views
  --_layouts
  
  ```
  
  In general this works fine but we encountered a problem with the index pages of sections.
  All pages are grouped in the views directory, so in views we could have a folder "articles" and within that a file "\_entry.twig" and "index.twig".
  
  For the entry to work we change the template path of the section in the backend.
  But there is no place to this for the index file.
  
  Anybody an idea how best to handel this?
  Is there a way to tell craft to also look in de \_views folder?
  
  **Tags:** templating, craft3, sections
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2018-09-13. Score: 3 | Accepted answer
  
  It sounds like you're wanting to move templates around like this:
  
  ```
  articles/index.html
  articles/_entry.html
  
  ```
  
  To this:
  
  ```
  _layouts/articles/index.html
  _layouts/articles/entry.html
  
  ```
  
  There are three basic ways Craft figures out what template to use based on the URL:
  
  * Element routing like `articles/_entry.html` (matches a URI in an element's settings, e.g. section or category)
  * [dynamic routes](https://docs.craftcms.com/v3/routing.html#dynamic-routes) and [URL Rules](https://docs.craftcms.com/v3/routing.html#dynamic-routes)
  * [Template path](https://docs.craftcms.com/v3/dev/#template-paths) routing like `articles/index.html`
  
  ([Craft 3 docs on routing](https://docs.craftcms.com/v3/routing.html))
  
  To get a URL like `http//example.com/articles` to use the template `_layouts/articles/index.html`, you have two options:
  
  1. Set up a dynamic route or URL rule.
  2. Create a Single with the URI set to `articles`.
  
  Personally, I often create a Single for this like a Blog index page. Then it's easy to control parts of the index page like a header image or custom SEO tags.
  
  A **dynamic route** would look like this:
  
  [![dynamic route example screenshot](https://i.sstatic.net/2ka4H.png)](https://i.sstatic.net/2ka4H.png)
  
  A **URL rules** would work something like this in `config/routes.php`:
  
  ```
  'articles' => ['template' => '_layouts/articles/index'],
  
  ```
  
  A third option that I don't recommend is if you have a structured section called something like "Pages" (or Static Pages or Landing Pages), you could create different Entry Types called "Page" and "Articles Index" just for this.
  
  ```
  ├── About Us (Page)
  │   └── Our Team (Page)
  ├── Articles (Articles Index)
  ├── Services (Page)
  └── Contact (Page)
  
  ```
  
  I'm not a fan of this for a few reasons, but the main one is that you can't point entry types to different templates in Craft so you'll probably have to use Twig includes to create a "routing template" that points the Article Index entry type to a different template. Also, chances are you will never need more than one Articles index page, and you won't want to drag and drop it's location around the structure because the URLs will become out of sync with the child Article entries.
  
  > **Comments:**
  > **username_0**: The problem solved itself when we realized we would need a single for each "index" page, just like your blog example. But it's good to know that the routes can be defined in the config.  
  
  ---
  
  ### Answer by username_2 on 2018-09-11. Score: 1
  
  You can't create a url path that goes to a \_\*\*\* folder. If you rename your folder without the underscore, it should work. Folders that uses underscores are kind of protected and can only be used by other templates.
  
  > **Comments:**
  > **username_3**: Unless you tell your structure/channel/whatever to look at an underscored template explicitly then it will work.  
  
  ---
  
  ### Answer by username_3 on 2018-09-11. Score: 1
  
  This is how my templates directory looks for almost every project:
  
  ```
  Templates
  --- _layout
  --- includes
  --- partials
  --- site
  --- users
  --- shop
  
  ```
  
  As long as your templates update their 'extend' tag to be `{% extends '_layout/base' %}` then Craft understands where that is. Craft is aware of everything in the templates directory, you don't need to set up much config except for things like the users login/password templates.
  
  My main site pages structure is setup in the CMS to look at `/site/_index.twig` then all the entry.types within this structure are based on this template and I include the entry type's appropriate template in my site base file.
  
  Let me know if you need more details.
  
  
  ---
  
  