Skip to content

Instantly share code, notes, and snippets.

@zeshanshani
Last active September 21, 2020 12:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zeshanshani/ccbfe8c0177a2513f0a92d0747349f50 to your computer and use it in GitHub Desktop.
Save zeshanshani/ccbfe8c0177a2513f0a92d0747349f50 to your computer and use it in GitHub Desktop.
Expand PHP conditionals in HTML in VS Code.
{
// ECHO
"PHP Echo Tag": {
"prefix": "echo",
"body": [
"<?php echo ${1:\\$var}; ?>"
],
"description": "Expand \"echo\" into PHP echo block"
},
// PHP Blocks
"PHP Block Tags": {
"prefix": "php",
"body": [
"<?php $0 ?>"
],
"description": "Expand PHP into block tags"
},
// PHP Open Blocks
"PHP Open Block Tags": {
"prefix": "phpf",
"body": [
"<?php",
"$0",
"?>"
],
"description": "Expand PHP into open block tags"
},
// IF Conditional
"IF Conditional": {
"prefix": "if",
"body": [
"<?php if ( ${1:expr} ): ?>",
" $0",
"<?php endif; ?>"
],
"description": "Expand 'if' into IF conditional"
},
// FOREACH Conditional
"FOREACH Conditional": {
"prefix": "foreach",
"body": [
"<?php foreach ( ${1:collection} as ${2:value} ): ?>",
" $0",
"<?php endforeach; ?>"
],
"description": "Expand 'foreach' into FOREACH loop"
},
// PHP Block Comments
"PHP Block Comments": {
"prefix": "phpcom",
"body": [
"<?php",
"/*",
"$1",
"*/",
"?>"
],
"description": "Expand PHP into open block tags"
},
// IF Conditional
"IF Conditional": {
"prefix": "if",
"body": [
"<?php if ( ${1:expr} ): ?>",
"\t$0",
"<?php endif; ?>"
],
"description": "Expand 'if' into IF conditional"
},
"IF Conditional - Bracket Structure": {
"prefix": "iftf",
"body": [
"<?php",
"if (${1:expr})",
"{",
"\t?>",
"\t$0",
"\t<?php",
"}",
"?>",
],
"description": "Expand 'if' into IF Conditional - Bracket Structure"
},
"ELSE Statement": {
"prefix": "else",
"body": [
"<?php else: ?>"
],
"description": "Expand 'else' into ELSE statement"
},
// FOREACH Conditional
"FOREACH Conditional": {
"prefix": "foreach",
"body": [
"<?php foreach ( ${1:\\$collection} as ${2:\\$value} ): ?>",
"\t$0",
"<?php endforeach; ?>"
],
"description": "Expand 'foreach' into FOREACH loop"
},
// FOREACH Conditional
"FOREACH Conditional - TeacherFunder": {
"prefix": "foreachtf",
"body": [
"<?php",
"foreach (${1:\\$collection} as ${2:\\$value})",
"{",
"\t?>",
"\t$0",
"\t<?php",
"}",
"?>"
],
"description": "Expand 'foreach' into FOREACH loop"
},
// White Conditional
"While Conditional": {
"prefix": "while",
"body": [
"<?php while ( ${1:\\$variable} ): ?>",
"\t$0",
"<?php endwhile; ?>"
],
"description": "Expand 'while' into WHILE loop"
},
}
@OksanaRomaniv
Copy link

Thank you from another WP dev that is struggling with VS code :)

@zeshanshani
Copy link
Author

@OksanaRomaniv - you're most welcome and thank you for starring this gist. I see you're a Genesis Expert :)

VS Code is really a great editor, but I think it'll take a lot of time until it gets fully compatible with all the WP and PHP developers' requirements. I think by collaborating together, we can make it a lot better. 💯

I'll continue doing my testing and will keep expanding this gist and create new ones. If you get something, you can share it too, would love to see. :)

@clopezpro
Copy link

soy nuevo usando VsC, a donde debería colocar este codigo?

@SharakPL
Copy link

SharakPL commented Jan 24, 2018

@khrystyan88 File -> Preferences -> User snippets, then look for html on the list and paste above code in newly opened html.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment