Skip to content

Instantly share code, notes, and snippets.

@Stenerson
Created October 17, 2023 14:49
Show Gist options
  • Save Stenerson/541fe235630e7c726b96477ff27a705b to your computer and use it in GitHub Desktop.
Save Stenerson/541fe235630e7c726b96477ff27a705b to your computer and use it in GitHub Desktop.
PHP Short Tag Snippets for VS Code

To add these specific snippets (and persist them over update) :

  1. Edit User Snippets under Code > Preferences on macOS, File > Preferences on Windows
  2. Copy this gist's content under the specific VS Code context (HTML in this case)
  3. Snippets are now available in HTML context
{
"<?php If ... endif": {
"prefix": "pif",
"body": [
"<?php if (${1:condition}): ?>",
"\t${0:<!-- code here -->}",
"<?php endif; ?>"
],
"description": "If endif block inside HTML"
},
"<?php else: ?>": {
"prefix": "pelse",
"body": [
"<?php else: ?>"
],
"description": "php else inside HTML"
},
"<?php If ... else ... endif": {
"prefix": "pifelen",
"body": [
"<?php if (${1:condition}): ?>",
"\t${2:<!-- code here -->}",
"<?php else: ?>",
"\t${0:<!-- code here -->}",
"<?php endif ?>;"
],
"description": "If else endif block"
},
"<?php else: ?>": {
"prefix": "pelif",
"body": [
"<?php elseif (${1:condition}): ?>",
"\t${0:<!-- code here -->}",
],
"description": "php elseif inside HTML"
},
"<?php If ... elseif ... else ... endif": {
"prefix": "pifelifen",
"body": [
"<?php if (${1:condition}): ?>",
"\t${2:<!-- code here -->}",
"<?php elseif (${3:condition}): ?>",
"\t${4:<!-- code here -->}",
"<?php else: ?>",
"\t${0:<!-- code here -->}",
"<?php endif; ?>"
],
"description": "If elseif else endif block"
},
"<?php foreach() ... endforeach": {
"prefix": "pforeach",
"body": [
"<?php foreach (\\$${1:iterable} as \\$${2:value}): ?>",
"\t${0:<!-- code here -->}",
"<?php endforeach;?>",
],
"description": "foreach inside HTML"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment