Last active
September 21, 2020 12:44
Expand PHP conditionals in HTML in VS Code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// 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 - 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. :)
soy nuevo usando VsC, a donde debería colocar este codigo?
@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
Thank you from another WP dev that is struggling with VS code :)