Search code examples
phpsublimetext3sublimetextcode-snippets

How to escape $ on Sublime Text Snippet


I create a snippet for my PHP laravel in SBT3

<snippet>
    <content><![CDATA[
dd("${1}",${1});
]]></content>
    <tabTrigger>dd</tabTrigger>
    <scope>source.php</scope>
</snippet>

When I typed dd

I see this now.

enter image description here

if I type more

enter image description here

notice it's wrong ?

It need have the $ like this

dd("nameofTheVariable",$nameofTheVariable);

How do I modify my snippet to escape the $?


Solution

  • The nameofTheVariable is stored in ${1}, so you'll need to add another $ before it.

    Use a backslash (\) to escape it: dd("${1}",\$${1});

    <snippet>
        <content><![CDATA[
    dd("${1}", \$${1});
    ]]></content>
        <tabTrigger>dd</tabTrigger>
        <scope>source.php</scope>
    </snippet>
    

    Output

    Note: I've placed a space ( ) after the comma (,) as PSR-2 prefers it.