1

When I comment out a line of strictly PHP code using my keybind (ctrl+/), the entire line is commented out and becomes grey in color, as desired. The same is true for a line of strictly HTML code. But if execute the same keybind on a line that is a mix of HTML and PHP code, e.g.

<img width="<alt="<?php echo esc_attr( $spacious_slider_title ); ?>">

the entire line does not become grey in color. Only the HTML portions of the line become grey (screenshot example). Plus, in that case, I believe the PHP code will still execute. Is there a way to completely comment out a line of mixed syntax code like this, ensure the PHP code does not execute, and have the line completely greyed out in VS Code, with a single keystroke? If so, how would I approach that?

My current course of action in these cases is to carry out the comment keybind, which wraps the line in HTML comments. After, I will manually add a // before the PHP code to also comment it out. I'm hoping there is a single keybind solution to this, as this sometimes becomes tedious.

I should perhaps note that I just installed VS Code and am learning it. I am coming from SublimeText, so the first thing I did was install SublimeText keybinds. This was an issue with SublimText as well, and I don't believe there was a solution.

I've seen this previous question (How to comment out both HTML and PHP in PHP inside HTML?). While it is related, it doesn't exactly answer my particular question about a VS Code keybind.

5
  • FWIW, this works for me in PhpStorm, you end up with this: <!--<img width="<alt="--><?php //echo esc_attr( $spacious_slider_title ); ?><!--">--> Would you consider switching? ;) Commented Nov 13, 2018 at 11:21
  • 1
    @Davіd not the OP but I too am facing the above issue and I would absolutely switch to PhpStorm (I used to use before), if it had a community edition as it does with IntelliJ IDEA. Commented Nov 13, 2018 at 11:22
  • @Script47 Ah, 'tis true, that's such a pity. It's a really great IDE, but very expensive :( Commented Nov 13, 2018 at 11:26
  • @Davіd At this point, since I'm just now getting into the swing of things with VS Code (after a migration from SublimeText), I probably wouldn't be interested in switching to PHP Storm. But if VS Code presents me with more challenges like this, I may consider it. Commented Nov 20, 2018 at 7:59
  • @Davіd I know what you mean. But, to be honest, PhpStorm is actually cheaper than Netflix. Commented Nov 22, 2018 at 18:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.