Is it possible to comment out a line of mixed syntax code (PHP + HTML) with a single keybind?
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.
php html visual-studio-code
add a comment |
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.
php html visual-studio-code
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? ;)
– Davіd
Nov 13 '18 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.
– Script47
Nov 13 '18 at 11:22
@Script47 Ah, 'tis true, that's such a pity. It's a really great IDE, but very expensive :(
– Davіd
Nov 13 '18 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.
– cag8f
Nov 20 '18 at 7:59
@Davіd I know what you mean. But, to be honest, PhpStorm is actually cheaper than Netflix.
– Álvaro González
Nov 22 '18 at 18:22
add a comment |
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.
php html visual-studio-code
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.
php html visual-studio-code
php html visual-studio-code
asked Nov 13 '18 at 11:16
cag8fcag8f
196118
196118
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? ;)
– Davіd
Nov 13 '18 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.
– Script47
Nov 13 '18 at 11:22
@Script47 Ah, 'tis true, that's such a pity. It's a really great IDE, but very expensive :(
– Davіd
Nov 13 '18 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.
– cag8f
Nov 20 '18 at 7:59
@Davіd I know what you mean. But, to be honest, PhpStorm is actually cheaper than Netflix.
– Álvaro González
Nov 22 '18 at 18:22
add a comment |
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? ;)
– Davіd
Nov 13 '18 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.
– Script47
Nov 13 '18 at 11:22
@Script47 Ah, 'tis true, that's such a pity. It's a really great IDE, but very expensive :(
– Davіd
Nov 13 '18 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.
– cag8f
Nov 20 '18 at 7:59
@Davіd I know what you mean. But, to be honest, PhpStorm is actually cheaper than Netflix.
– Álvaro González
Nov 22 '18 at 18:22
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? ;)– Davіd
Nov 13 '18 at 11:21
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? ;)– Davіd
Nov 13 '18 at 11:21
1
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.
– Script47
Nov 13 '18 at 11:22
@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.
– Script47
Nov 13 '18 at 11:22
@Script47 Ah, 'tis true, that's such a pity. It's a really great IDE, but very expensive :(
– Davіd
Nov 13 '18 at 11:26
@Script47 Ah, 'tis true, that's such a pity. It's a really great IDE, but very expensive :(
– Davіd
Nov 13 '18 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.
– cag8f
Nov 20 '18 at 7:59
@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.
– cag8f
Nov 20 '18 at 7:59
@Davіd I know what you mean. But, to be honest, PhpStorm is actually cheaper than Netflix.
– Álvaro González
Nov 22 '18 at 18:22
@Davіd I know what you mean. But, to be honest, PhpStorm is actually cheaper than Netflix.
– Álvaro González
Nov 22 '18 at 18:22
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279827%2fis-it-possible-to-comment-out-a-line-of-mixed-syntax-code-php-html-with-a-si%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279827%2fis-it-possible-to-comment-out-a-line-of-mixed-syntax-code-php-html-with-a-si%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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? ;)– Davіd
Nov 13 '18 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.
– Script47
Nov 13 '18 at 11:22
@Script47 Ah, 'tis true, that's such a pity. It's a really great IDE, but very expensive :(
– Davіd
Nov 13 '18 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.
– cag8f
Nov 20 '18 at 7:59
@Davіd I know what you mean. But, to be honest, PhpStorm is actually cheaper than Netflix.
– Álvaro González
Nov 22 '18 at 18:22