What are .phtml files and when should I use them?

10

Until recently, I had never heard of phtml , however recently I see that it is being used a lot, mainly by some frameworks (such as Zend2).

Since I can usually put html content inside a .php file, I ask myself what is the use of a .phtml file?

Some points you might like to know:

  • Does it have any performance or performance advantages?
  • When should I opt for the .phtml extension?
  • Has this extension been created for what purpose?
asked by anonymous 05.12.2014 / 12:01

2 answers

15

Normally there is no difference from one type of file to another in rendering the page. It's more of a commodity for programmers when project grows.

Usually:

  • .PHP files contain nothing related to View (HTML, JS, CSS ...)
  • Files .PHTML contains the minimal logic required, if any, to render and display what comes from the Models by the Controllers.

The .phtml extension itself was the default file extension for programs created in PHP 2. The .php3 extension took its place in PHP 3 and when PHP 4 reached the extension was universalized as .php , although it does exist and be used for a while. .php4 .

Nowadays the old extensions can still be seen in use, ending just setting the relationship between extension and Content-type by the server that anything can run as a PHP program. But that's pretty weird.

> Source

    
05.12.2014 / 12:18
0

It is interesting to also say that php files can be displayed without a web server, obviously the php itself will not be rendered, but the html can be seen, thus facilitating code changes in any environment.

    
19.03.2018 / 12:37