webksde / ddev-vscode-devcontainer-drupal-template

Drupal DDEV based development container with attached Visual Studio Code
22 stars 3 forks source link

Provide Twig Code Completion / Snippets #150

Open thomasfrobieter opened 8 months ago

thomasfrobieter commented 8 months ago

In the .vscode folder, provide some usefull Twig Snippets, using a .code-snippets file ("drupal_twig.code-snippets"):

{
        "tpl_extend": {
          "scope": "twig",
          "prefix": "extend",
          "body": [
              "{% extends \"$1$RELATIVE_FILEPATH\" %}",
              "$2"
          ],
          "description": "Add Twig tpl extend"
        },
        "block_parent_content": {
            "scope": "twig",
            "prefix": "parent",
            "body": [
                "{{ parent() }}",
            ],
            "description": "Add Twig Block parent contents"
        },
        "get_specific_block_from_template": {
          "scope": "twig",
          "prefix": "block",
          "body": [
              "{{ block('$1', '@drowl_base/$2.html.twig') }}",
          ],
          "description": "Add Twig Block parent contents"
        },
    "twig_attach_library": {
        "scope": "twig",
        "prefix": "attach",
        "body": [
            "{{ attach_library('drowl_base/$0') }}"
        ],
        "description": "Twig / Drupal Attach library"
    },
    "twig_kint": {
        "scope": "twig",
        "prefix": "kint",
        "body": [
            "{{ kint($0) }}"
        ],
        "description": "Twig / Drupal Kint Debug output"
    },
    "twig_dsm": {
        "scope": "twig",
        "prefix": "dsm",
        "body": [
            "{{ dsm($0) }}"
        ],
        "description": "Twig / Drupal DSM Debug output"
    },
    "twig_spaceless": {
        "scope": "twig",
        "prefix": "space",
        "body": [
            "{% apply spaceless %}$0{% endapply %}"
        ],
        "description": "Twig spaceless with apply (spaceless is deprecated)"
    },
    "twig_translation_with_context": {
        "scope": "twig",
        "prefix": "|t",
        "body": [
            "|t({}, {'context' : '$0'})"
        ],
        "description": "Twig Drupal Translation strings with context"
    },
    "twig_real_content_module_filter": {
        "scope": "twig",
        "prefix": ["|real_content", "empty"],
        "body": [
            "|real_content is not empty"
        ],
        "description": "Check Markup (string) for 'real' content (empty check, requires drupal/twig_real_content)."
    },
    "twig_real_content_module_test": {
        "scope": "twig",
        "prefix": ["is real content", "is not empty"],
        "body": [
            "is real_content"
        ],
        "description": "Check Markup (string) for 'real' content (empty check, requires drupal/twig_real_content)."
    },
}
JPustkuchen commented 8 months ago

Alternatively check for a Drupal Twig plugin which handles this for us?

https://marketplace.visualstudio.com/items?itemName=nadim-vscode.twig-code-snippets looks good and relatively up to date in contrast to others. Lists Drupal support.

joshsedl commented 6 months ago

Alright, I added the extension, @thomasfrobieter, please check, if it fulfills your desires.