25

I am using Visual Studio Code on a Mac to work on WordPress applications.

Is there a way to make Visual Studio Code recognize HTML and use it's features (mainly autocompletion) inside PHP files?

I've searched for this answer before but just get told to Go to Visual Studio Code Settings: File >> Preferences >> User Settings

// Place your settings in this file to overwrite the default settings
{                
// Configure file associations to languages (e.g. "*.extension": "html"). These have precedence over the default associations of the languages installed.
     "files.associations": {"*.php": "html"}     
 }

But doing this makes you lose all PHP support and autocompletion.

I wish Microsoft would realize that PHP developers commonly use PHP and HTML together when creating applications/websites. I would love to use VS Code instead of the magnificent but expensive PHP storm if possible.

Gama11
  • 28,518
  • 9
  • 66
  • 91
thatemployee
  • 453
  • 1
  • 6
  • 12
  • I can remember I used a extension once, I am not sure if the intellisense worked well. Check this post: https://stackoverflow.com/questions/10529214/how-to-use-php-with-visual-studio – Stefan Aug 29 '17 at 20:42
  • @Stefan thank you for the link but it seems as if these are paid which would defeat the purpose of using a open source editor for me, and I might as well just stick to a better option such as PHPStorm. – thatemployee Aug 29 '17 at 20:45
  • Ah, yes, I didn't read very well. It is worth the effort to do a bit of goolging for them. There is a free one around somewhere. Too bad I can't remember the name :/ – Stefan Aug 29 '17 at 20:48
  • Somehow I don't feel PHP is high on Microsoft's list of priorities. You know, since PHP is a competitor for ASP.NET etc. in that space... – Jonnix Aug 29 '17 at 20:50
  • 2
    "PHP developers commonly use PHP and HTML together" I would actually advise against that whenever possible. – Patrick Q Aug 29 '17 at 20:53
  • 1
    @PatrickQ Yeah because it's totally possible to not use HTML inside template.php files. Common now. – thatemployee Aug 29 '17 at 20:54
  • 2
    @JonStirling Then maybe Microsoft shouldn't try and claim they have 'Fantastic PHP support' – thatemployee Aug 29 '17 at 20:55
  • Define support. Let's face it, all you need to build a PHP web app is the PHP CLI and a text editor and hey presto, you're supported. Add syntax highlighting and suddenly it's fantastic support :P – Jonnix Aug 29 '17 at 20:57
  • Such as HTML autocompletion inside PHP files. Yes, syntax highlighting is the whole purpose of this question. Did you not even read it? @JonStirling – thatemployee Aug 29 '17 at 20:59
  • I can't tell you the last time I had raw HTML in a `.php` file (aside from small, quoted, snippets). It most certainly is possible. If you're creating templates, consider naming them something like `.tpl` or just use a templating system like twig or smarty. – Patrick Q Aug 29 '17 at 21:00
  • That's awesome if you are using your own projects. But I, and 99% of existing code bases for client work in agencies do not. @PatrickQ – thatemployee Aug 29 '17 at 21:01
  • 2
    `99% of existing code bases for client work in agencies do not.` Nope. – Jonnix Aug 29 '17 at 21:02
  • 2
    Well if you will come up with ludicrous statements... anyway... moving on. – Jonnix Aug 29 '17 at 21:04
  • Like your first comment that rephrased exactly what I asked? Yes most WordPress agencies don't use twig or smarty. Not every agency is a godsend that uses best practices. You out of all people should know that. – thatemployee Aug 29 '17 at 21:06
  • Although I didn't down-vote I can imagine that expressing your wish in the end can lead to opinion based reactions which is out off scope on this site. For this reason I will vote to close this question because it seems to attract an unwanted discussion. Perhaps, you can try to ask the question in a different form. – Stefan Aug 29 '17 at 21:53
  • 2
    @Stefan Ah yes, maybe I shouldn't have added my opinion at the end and just left it as a question only. Didn't think people on StackOverflow were so sensitive, lesson learned. Thanks for the insight. – thatemployee Aug 29 '17 at 22:53
  • Chekout the official docs: https://code.visualstudio.com/docs/languages/php https://marketplace.visualstudio.com/search?term=php&target=VSCode&category=All%20categories&sortBy=Relevance – Paul Melero Apr 05 '18 at 13:36
  • It's not possible at current moment with native functionality. Please take a look on issue: https://github.com/Microsoft/vscode/issues/1751 – ColCh Oct 26 '18 at 16:32
  • Don't think anyone's pointed this out, but if you're willing to cough up a few pennies you can get decent PHP/HTML/JS/CSS support from Devsense's PHP Tools extension for VS Code. https://marketplace.visualstudio.com/items?itemName=DEVSENSE.phptools-vscode – AndyM84 Nov 24 '18 at 05:09
  • Sadly I've had the same issue with VSCode, I switched to using Sublime Text, Atom is good and Codeanywhere is great for FTP editing. – Tomas Crofty Nov 30 '18 at 12:28
  • Atom does this perfectly – MikeeeGeee Mar 18 '19 at 09:20

3 Answers3

7

As far as I can tell, it does. Take a look at this php file I have created in VS Code (no extensions), with HTML inside the file with syntax highlighting for both languages. enter image description here

There is a button (It should say the word PHP) in the bottom right corner of the screen that allows you to switch the syntax highlighting and autocompletion to another language, and while this does temporarily turn off PHP syntax, it will allow you to code in HTML a lot easier.

Jodast
  • 1,253
  • 1
  • 17
  • 32
5

You can install this plugin: PHP Intelephense

Brentspine
  • 226
  • 10
Saket89
  • 131
  • 3
  • 10
2

You can enable html support in any language by adding the following to your settings.json file:

"emmet.includeLanguages": {
    "your-language": "html",
    "rust": "html",
    "php": "html",
    "javascript": "html",
}