djangokillen
djangokillen

Reputation: 161

Variables In Sublime Text 3 Snippets

In PHPStorm, when creating a snippet, you can do something like this:

<!-- $VALUE$ Form Input -->
<div class="form-group">
    <input type="text" name="$NAME$" class="form-control">
</div>

With variables and such, so you can easily write a value. I'm wondering how to do the same thing with Sublime Text 3. This is what I have in my CDATA tag:

<!-- $VALUE Form Input -->
<div class="form-group">
    <input type="text" name="$NAME" class="form-control">
</div>

However, it's not working.

Upvotes: 2

Views: 2599

Answers (1)

MattDMo
MattDMo

Reputation: 102852

Unfortunately, the only variables that are available in snippets are specified in the docs under snippets environment-variables, as well as any you declare in a .tmPreferences metadata file, or in a .sublime-options file. However, you can have predefined values in snippets. For example, this snippet:

<snippet>
    <content><![CDATA[<!-- ${1:VALUE} Form Input -->
<div class="form-group">
    <input type="text" name="${2:NAME}" class="form-control">
</div>$0]]></content>
    <tabTrigger>form_group</tabTrigger>
    <scope>text.html</scope>
</snippet>

gives this result when triggered:

You can then hit Tab and the focus will move from field 1 to field 2:

and again to move to the exit point $0:

Upvotes: 3

Related Questions