I'm building a Model-View-Controller framework, and it has come time to decide how I will be creating and using view templates and layouts.

Some frameworks use special extensions for these files. CakePHP uses .ctp.

I have heard-of/seen .tpl files, though I've never used them myself.

There is the .inc extension, which doesn't feel right, and of course, I could stick with plaon ol' .php.

For that matter why not .awesome?

What do you use for your template files? Is there any benefit to using a special file extension for these files? Are you partial to a certain extension for nostalgia or convention alone? They're typically (and will be in my project) already in their own directory, so I assume there must be some reason they are differentiated by their extension in projects like CakePHP.

5 Answers 5


Call them whatever you will. Just make sure they are consistent. Ideally, files with different purposes have different extensions, meaning you probably shouldn't use .php as you are missing out on a chance to differentiate the files at a glance.

Something you should always take into consideration when coming up with your own extensions is how the web-server will handle it. For example, do you want external users potentially downloading your raw templates if they someone deduce/guess the path/filename? If not, make sure you update your server's configuration to disallow access to those resources.


For Smarty templates, the standard is .tpl.

For Twig templates, the standard is .twig.

For Latte templates, the standard is .latte.

For Mustache templates, the standard is .mustache.

For CakePHP templates, the standard is .ctp.

If you create your own templating engine, it's best to avoid any of these five standards to avoid confusion. Any other extension that isn't already commonly associated with another filetype would do fine. Either that, or you could just go for .html / .xml if your templates are valid .html / .xml.

Whichever extension you pick and whichever template type you pick, it's always best to go for an extension that's recognised by your IDE. If you don't, auto-formatting and code highlighting features of your IDE have to be set manually or can't be set at all, which makes your template system less user friendly.


I'm often using a DOS-reminiscent .htm extension. Where through the incomplete extension I try to denote an incomplete HTML file. (Because it mostly just contains a portion of the site template. And ideally it just contains sparse PHP and presentation logic code.)

  • I forgot about that one.
    – Stephen
    Commented Jan 27, 2011 at 3:14

I use .tpl for template files. Everything else is usually just .php.

One reason to use different file extensions is to make it easier to configure your webserver to not serve up files of that type (assuming you dont want it to do that).


I use .xml because I developed an XML-based template system for my personal needs. The great thing about it is that all the template fragments are valid XML in themselves (ensuring the final result sent to the browser is valid XHTML too) and it provides a nice way to merge different stylesheet and script needs without resorting to some ugly $scripts_go_here variable inside a single header. It's a little bit verbose though.

That said, I don't really mind how they're called. As long as they're at the same place and that they have the same extension, I don't think it really changes anything.

Not the answer you're looking for? Browse other questions tagged or ask your own question.