Adax
Adax

Reputation: 17

How can i have two snippets for PHP in VSCode?

This is how I imagined that I could do it but I see that it is overwritten and only the last one is working:

{
    "php": {
        "prefix": "php",
        "body": [ "<?php $1 ?>" ],
        "description": "php tag",

        "prefix": "echo",
        "body": [ "echo \"$1\";" ],
        "description": "php tag"
    }
}

Thanks!

Upvotes: 1

Views: 174

Answers (1)

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146460

That's not even valid JSON. You should be getting green squiggly lines that display Duplicate object key on hover:

Duplicate object key

You need to edit the snippets\php.json file and add several sub-objects to the top-level object identified by different key names; such key is meant to contain the snippet name, not the language, which is already set in the file name:

{
    "PHP tags": {
        "prefix": "php",
        "body": [ "<?php $1 ?>" ],
        "description": "php tag"
    },
    "echo statement": {
        "prefix": "echo",
        "body": [ "echo \"$1\";" ],
        "description": "php tag"
    }
}

Upvotes: 1

Related Questions