ST3代码段:触发HTML代码段但不在PHP范围内

时间:2014-03-18 12:18:48

标签: sublimetext code-snippets sublimetext3

PHP:

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

HTML(以及带有html的.php文件)

<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>

如何在第二个代码段上启用“ text.html.basic ”而不会在我使用PHP文件时触发它,因为它也是“ text.html.basic source.php。%

1 个答案:

答案 0 :(得分:3)

注意:您在HTML代码段中有一个多余的(我已经过时)</script>结束标记。

你需要做的是:

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>

正如您所看到的,HTML代码段取消source.php范围与-(减号)