<p>Yes, prefixing a template's filename with an underscore does what it says on the box – any underscored template will be excluded from route mapping.</p>

<p>A typical use case is to use underscores for partials or wrappers, e.g. "_mainmenu.html" or "_baseTemplate.html" – essentially any template that doesn't make any sense to load up or access directly in the browser via that template's path.</p>

<p>This isn't a mandatory thing, but a good practice.</p>

CC BY-SA 3.0
2015-04-01T15:11:25.947Z
It actually is required if you want to prevent URI to tempate routing for that URI (→ [routing case 6](http://buildwithcraft.com/docs/routing)).
carlcs
CC BY-SA 3.0
2015-04-01T15:20:10.203Z
Good point, @carlcs.
Mats Mikkel Rummelhoff
CC BY-SA 4.0
2018-06-29T06:45:06.590Z
It's an old topic, but I found it since I was looking for the meaning of prefixing underscores for folder names and I could only find this topic. 
So I might be asking a dumb question, if so, my sincere apologies :-), but I'm wondering: what does prefixing underscores for folder names do? Does that mean that all templates in that folder are being excluded from route mapping so you don't need a prefixed underscore for all templates inside that folder? 
I now do both: prefixing my folder and prefixing my template name, but I'm wondering if that's too much...
Jan
CC BY-SA 4.0
2018-06-29T22:32:48.270Z
@Jan Right, if you prefix a folder name w/ an underscore, everything inside that folder (both templates and subfolders) will be excluded from routing. Hence, it’s not necessary to underscore a template sitting in an underscored folder.
Mats Mikkel Rummelhoff
CC BY-SA 4.0
2018-07-03T11:04:37.833Z
Thanks for the answer, now I know for once and for all :-) !
Jan
CC BY-SA 4.0
2019-07-29T13:18:13.173Z
Is there any way to override this behaviour on a local environment? (We have Commerce email templates in an _email folder and sometimes need to test them locally, which means renaming the folder, then renaming it back again)
James Greig
CC BY-SA 3.0
2015-04-01T15:03:52.863Z
2015-04-01T15:03:52.863Z
Mats Mikkel Rummelhoff
<p>More of a question than problem; I see this often - templates that start with an underscore. For example, <code>_entry.html</code>.</p>

<p>Reading the Craft docs:</p>

<blockquote>
  <p>Note that if any of the URI segments begin with an underscore ('_'), Craft will return a 404, since template path segments that begin with an underscore are considered "hidden" from direct access</p>
</blockquote>

<p>I guess I'm confused as to what I am hiding <em>from</em>. Is it so I can't directly browse right to the full path of that template?</p>

<p><code>mysite.com/something/something/_template.html</code></p>

<p>If you move the craft folder outside of the site root, I can't really get to that file can I? It just isn't obvious to me (yet) what the benefit is and when/where/why I need to start a template with and underscore.</p>

<p>Thank you!</p>

<templating><routes>
Routing templates thats start with an underscore
# Routing templates thats start with an underscore

(Asked by: username_0 on 2015-04-01)

More of a question than problem; I see this often - templates that start with an underscore. For example, `_entry.html`.

Reading the Craft docs:

> Note that if any of the URI segments begin with an underscore ('\_'), Craft will return a 404, since template path segments that begin with an underscore are considered "hidden" from direct access

I guess I'm confused as to what I am hiding *from*. Is it so I can't directly browse right to the full path of that template?

`mysite.com/something/something/_template.html`

If you move the craft folder outside of the site root, I can't really get to that file can I? It just isn't obvious to me (yet) what the benefit is and when/where/why I need to start a template with and underscore.

Thank you!

**Tags:** templating, routes

---

## 1 answers

### Answer by username_1 on 2015-04-01. Score: 8 | Accepted answer

Yes, prefixing a template's filename with an underscore does what it says on the box – any underscored template will be excluded from route mapping.

A typical use case is to use underscores for partials or wrappers, e.g. "\_mainmenu.html" or "\_baseTemplate.html" – essentially any template that doesn't make any sense to load up or access directly in the browser via that template's path.

This isn't a mandatory thing, but a good practice.

> **Comments:**
> **username_2**: It actually is required if you want to prevent URI to tempate routing for that URI (→ [routing case 6](http://buildwithcraft.com/docs/routing)).  
> **username_1**: Good point, @carlcs.  
> **username_3**: It's an old topic, but I found it since I was looking for the meaning of prefixing underscores for folder names and I could only find this topic.  So I might be asking a dumb question, if so, my sincere apologies :-), but I'm wondering: what does prefixing underscores for folder names do? Does that mean that all templates in that folder are being excluded from route mapping so you don't need a prefixed underscore for all templates inside that folder?  I now do both: prefixing my folder and prefixing my template name, but I'm wondering if that's too much...  
> **username_1**: @Jan Right, if you prefix a folder name w/ an underscore, everything inside that folder (both templates and subfolders) will be excluded from routing. Hence, it’s not necessary to underscore a template sitting in an underscored folder.  
> **username_3**: Thanks for the answer, now I know for once and for all :-) !  
> **username_4**: Is there any way to override this behaviour on a local environment? (We have Commerce email templates in an _email folder and sometimes need to test them locally, which means renaming the folder, then renaming it back again)  

---

