how do you tell phpstorm to treat a file .html as a php file?

I'm in a Mac.
I tried Alt-Enter to use the language injection, but it doesn't bring the intention actions dialog. Just for fun, I tried Alt-Enter in a .php file and it worked.


1 comment
Comment actions Permalink

Hi there,

In PHP code you can inject language in any string. Where do you plan to inject (and what language) in HTML? All standard places already have languages injected automatically (like, inline CSS or inline JS etc).

But if you want to inject something in HTML file, you can create automatic rule in "Preferences | Language Injections".

In any case: PHP is NOT listed as one of the available injectable languages.

How do you tell PhpStorm to treat a file .html as a php file?

You need to assign *.html pattern to "PHP files" instead of default "HTML files" in "Preferences | File Types". Since this is an IDE-wide setting, it will affect ALL projects.

The best way would be to give that file another extension and assign it to "PHP files". The most common extension used just for such purposes (not just inside PhpStorm, but overall) is *.phtml.


Please sign in to leave a comment.