Closed gabichuela85 closed 2 years ago
Thanks for sharing this, @gabichuela85!
To expound on this a bit, earlier in the semester when I shared info on VSCode snippets (https://github.com/susanBuck/e15-spring22/issues/4) I shared the code for a HTML specific snippet (snippets/html.json
). Language-specific snippet files can only work for that specific language. E.g. snippets defined in a html.json
snippet file can only apply to files ending with a .html
extension.
If you want a snippet to be able to apply to different file types (such as .php
, or .blade.php
), you should create a global snippet file that ends with the extension .code-snippets
.
Then, as @gabichuela85 noted - within this file you can set a scope indicating what file extensions the snippet should work in/for. (Or, you can omit the scope and it will work in any file type.)
As an example, you could have /snippets/html.code-snippets
with the following config:
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages.
"HTML Template": {
"scope": "html,blade,php",
"prefix": "html",
"body": [
"<!doctype html>",
"<html lang='en'>",
"<head>",
" <title></title>",
" <meta charset='utf-8'>",
" <link href=data: , rel=icon>",
"</head>",
"<body>",
"$0",
"</body>",
"</html>"
],
"description": "HTML Template"
},
}
Thanks again for posting, @gabichuela85.
I was just experimenting with this recently. I put a snippet into php.json
where I wanted HTML boilerplate to be available for my .php
files. I couldn't get the snippet to appear. When I instead wrote it into a workspace snippet (scoped to html and php), it properly worked.
I don't know if anyone else is using snippets in VS Code, but I ran into an issue attempting to use snippets in the bookmark app we're creating. None of mine were coming up.
I tried initially to add this line of code to a global snippet I had already set up, but wasn't successful. To fix the issue I went ahead and added a new HTML snippet to my app. To the snippet I added the following line: