user3433010
user3433010

Reputation:

ST3 snippet: trigger HTML snippet but not on PHP scope

PHP:

<snippet>
    <content><![CDATA[
foreach (\$${1} as \$${2:k}=>\$${3:v}) {
    ${4}
}
]]></content>
    <tabTrigger>fore</tabTrigger>
    <scope>source.php</scope>
</snippet>

HTML (and on .php files with html)

<snippet>
    <content><![CDATA[
<?php foreach (\$${1} as \$${2:k}=>\$${3:v}) : ?>
    ${4}
<?php endforeach; ?>
</script>
]]></content>
    <tabTrigger>fore</tabTrigger>
    <scope>source.html, text.html.basic</scope>
</snippet>

how can I enable "text.html.basic" on the second snippet without making it trigger when I'm on a PHP file, since it's also "text.html.basic source.php.%"

Upvotes: 2

Views: 937

Answers (1)

Sergey Telshevsky
Sergey Telshevsky

Reputation: 12197

Note: you have an excess (as I persume) </script> ending tag in HTML snippet.

What you have to do is this:

HTML

<snippet>
    <content><![CDATA[
<?php foreach (\$${1} as \$${2:k}=>\$${3:v}) : ?>
    ${4}
<?php endforeach; ?>
]]></content>
    <tabTrigger>fore</tabTrigger>
    <scope>text.html - source.php</scope>
</snippet>

PHP

<snippet>
    <content><![CDATA[
foreach (\$${1} as \$${2:k}=>\$${3:v}) {
    ${4}
}
]]></content>
    <tabTrigger>fore</tabTrigger>
    <scope>source.php</scope>
</snippet>

As you may see, the HTML snippet negates the source.php scope with a - (minus) sign

Upvotes: 3

Related Questions