2
"snippet with class binding":{
    "prefix": "row.${variable}",
    "body":[
        "<table class=\"row ${same_variable_here}\">",
        "\t<tr>",
        "\t\t<td>",
        "\t\t\t$0",
        "\t\t</td>",
        "\t</tr>",
        "</table>"
    ]
}

Is it possible(and how if so) to create variables like some_entity.classname expanding into something like this(in html for example):

<div class="classname"></div>
dreftymac
  • 31,404
  • 26
  • 119
  • 182
Andrew U.
  • 23
  • 1
  • 4

1 Answers1

3

It looks like you have two questions there. Yes, emmet expansion will automatically turn div.myClass into <div class="myClass"></div>. See emmet in vscode.

Your other question is about a emmet snippet for a full table expansion. See custom emmet snippets. In your settings.json you will need:

  "emmet.extensionsPath": "C:\\Users\\Mark\\.vscode\\extensions"

That should point to a folder that contains a new file that you will create called snippets.json. In that file put:

{
  "html": {
    "snippets": {
        "tableR": 
          "table.row.$1>tr>td"
    }
  }
}

Use whatever prefix you want besides "tableR". Then you must reload vscode. Then type your prefix and tab to expand (assuming you have the emmet tab expansion setting in your settings.]

[EDIT]: Based on your comment below, perhaps you are looking for something as simple as a snippet with a keybinding:

{
    "key": "ctrl+alt+n",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": {
      "snippet": "${TM_SELECTED_TEXT/(.*)\\.(.*)/<$1 class=\"$2\"><\\/$1>/}"
    }
},

So if you select anyTag.someClass becomes <anyTag class="someClass"></anyTag> when you use whatever keybinding you have chosen. Emmet is not involved here, this is just a simple keybinding in your keybindings.json (you can limit it to certain languages if you wish). Emmet expansion does not allow you to transform its prefix (the regexp above) the way a plain snippet can grab the selection or current word and transform it.

Mark
  • 143,421
  • 24
  • 428
  • 436
  • _emmet expansion will automatically turn div.myClass into
    . See emmet in vscode._ << Mostly my question is about this part, but implemented on a snippet: to turn 'snippet_name.var' **in a structure with autofilled var**(fill class _not_ by using tabstop, _but_ from emmet phrase)
    – Andrew U. Aug 28 '18 at 13:05
  • Please edit your question. "In a structure with autofilled var" I could guess at what you mean by that but you should make it explicit in your question with a good example. – Mark Sep 01 '18 at 04:31
  • So, i think edited section of your answer is almost satisfying my question. Still bad that snippets themselves isn't emmet-like. – Andrew U. Sep 10 '18 at 13:36