Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Create New Javascript Snippet

I am fairly new to snippet creation. I have successfully created multiple snippets for C# and HTML. When I ran into troubles I started using the MS Snippet Designer. The trouble I had was when I created a snippet for JS using the following code:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>tjready</Title>
      <Author>admin</Author>
      <Description>
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>$().ready(function() {</Shortcut>
    </Header>
    <Snippet>
      <Code Language="javascript"><![CDATA[$().ready(function() {
//This is a test of the onready
    });]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

My goal is to create the snippet for either JS or CSHTML files. The above does not work in either type of file after an import using the Code Snippet Manager (Tools > CSM). I tried placing the snippet in both the html and JavaScript categories. I also tried modifying the language type of the snippet.

Does anyone see what I am doing wrong?

like image 557
JabberwockyDecompiler Avatar asked Nov 28 '25 18:11

JabberwockyDecompiler


1 Answers

For anyone else that comes across this as well, if you need to add a leading $, add two.

<Snippet>
  <Code Language="javascript"><![CDATA[$$().ready(function() {//This is a test of the onready    });]]></Code>
</Snippet>
like image 143
Kelvin Avatar answered Nov 30 '25 06:11

Kelvin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!