Creating several Snippets

Asked

Viewed 51 times

0

Good afternoon. I looked here (/search?q=%5Batom%5D+Snippets), but I couldn’t get help, so I decided to read this post.

I currently use phpStorm, but it is very heavy, so I will start testing the Atom.

I’m having a hard time recreating my Snippets that were on phpStorm and recreating on snippets.cson. Always appears Duplicate key.

How to create multiple Snippets in Atom?

################################################
#        JS
################################################
'.source.js':
   'Console log':
     'prefix': 'log'
     'body': 'console.log $1'

'.source.js':
  '$("#").val()':
    'prefix': '$'
    'body': '$("#").val()'

################################################
#        PHP
################################################
'.source.php':
  'Select':
    'prefix': 'select'
    'body': """
        $rs = $mysqli->query("SELECT * FROM tabela WHERE coluna = '".$_GET['id']."' ");
        $row_rs = $rs->fetch_assoc();
        $rowTotal = $rs->num_rows;
        echo $row_rs['nome'];
    """

################################################
#        HTML
################################################

'.source.html':
  'Controller text':
    'prefix': '?'
    'body': '<?= $resultado["###"]; ?>'

'.source.html':
  'Snippet Name':
    'prefix': 'Snippet Trigger'
    'body': """
    echo "<script>alert('Mensagem');</script>";
    """

VERSION 2

################################################
#        JS
################################################
'.source.js':
   'Console log':
     'prefix': 'log'
     'body': 'console.log $1'

  '$("#").val()':
    'prefix': '$'
    'body': '$("#").val()'

################################################
#        PHP
################################################
'.source.php':
  'Select':
    'prefix': 'select'
    'body': """
        $rs = $mysqli->query("SELECT * FROM tabela WHERE coluna = '".$_GET['id']."' ");
        $row_rs = $rs->fetch_assoc();
        $rowTotal = $rs->num_rows;
        echo $row_rs['nome'];
    """

  'Alert':
    'prefix': 'alert'
    'body': """echo "<script>alert('Mensagem');</script>";"""

################################################
#        HTML
################################################

'.source.html':
  'echo':
    'prefix': '?'
    'body': '<?= $resultado["###"]; ?>'


    'html5':
      'prefix': 'html5'
      'body': """
        <!DOCTYPE html>
        <html lang="pt-br">
        <head>
            <meta charset="utf-8"/>
            <title></title>

            <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        </head>
        <body>




        </body>
        </html>
      """

1 answer

0

As specified in documentation, just you set the source only once:

################################################
#        JS
################################################
'.source.js':
   'Console log':
     'prefix': 'log'
     'body': 'console.log $1'

  '$("#").val()':
    'prefix': '$'
    'body': '$("#").val()'

################################################
#        PHP
################################################
'.source.php':
  'Select':
    'prefix': 'select'
    'body': """
        $rs = $mysqli->query("SELECT * FROM tabela WHERE coluna = '".$_GET['id']."' ");
        $row_rs = $rs->fetch_assoc();
        $rowTotal = $rs->num_rows;
        echo $row_rs['nome'];
    """

################################################
#        HTML
################################################

'.source.html':
  'Controller text':
    'prefix': '?'
    'body': '<?= $resultado["###"]; ?>'

  'Snippet Name':
    'prefix': 'Snippet Trigger'
    'body': """
    echo "<script>alert('Mensagem');</script>";
    """
  • Hi Anderson, thanks for the help. Html snipts are not working, see image http://prntscr.com/nyi3sp

  • @James and the image makes clear the problem: indentation

  • What do you mean? How should it look?

  • The same way I put it in the answer

  • I copied and pasted in my file, just added one more Html5 call.

  • I updated my code by putting VERSION 2, please, for a look.

  • @Tiago See that snippet html5 is indented from the previous snippet. Just remove this indentation level. It should only be indented with 2 spaces, it has 4 spaces. In the cited documentation there are more details about the syntax used if you need.

  • I think I’m too dumb... It may be very clear to you, but I can’t see my failure :(

  • You know what indentation is?

  • snip (http://prntscr.com/nyiaay). Using (http://prntscr.com/nyiajy) the Html5 I created not being recognized.

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.