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

Asked

Viewed 7,882 times

12

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

Since I can normally put html content inside a file .php, I wonder what is the use of using a file .phtml?

Some points I would like to know:

  • It has some performance or interpretation advantage?
  • When should I choose the extension .phtml?
  • This extension was created for what purpose?
  • It is also interesting to say that phtml files can be displayed without a web server, obviously php itself will not be rendered, but html can be seen, thus facilitating code changes in any environment.

1 answer

21


Usually there is no difference from one file type to another when it comes to rendering the page. It is another commodity for programmers when project grows

Normally:

  • PHP files. does not contain anything related to View (HTML, JS, CSS...)
  • Files . PHTML contains the minimum logic needed, if any, to render and display what comes from Models by Controllers.

The extent .phtml itself was the default file extension in the programs created in PHP 2. The extension .php3 took its place in PHP 3 and when PHP 4 arrived the extension was universalized as .php, despite existing and being used for a certain time .php4.

Nowadays old extensions can still be seen in use, after all just configure the relationship between extension and Content-type by the server that anything can run as a PHP program. But this is quite rare.

> Source

  • 1

    If my answer (currently the only one) solved your "problem" (which to me seemed more of a curiosity), mark it as solved. Your doubt today may be someone else’s tomorrow. ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.