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 and URL Rules
- Template path routing like
articles/index.html
(Craft 3 docs on routing)
To get a URL like http//example.com/articles
to use the template _layouts/articles/index.html
, you have two options:
- Set up a dynamic route or URL rule.
- 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:
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.