Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Twig Code Completion / Snippets #150

Open
thomasfrobieter opened this issue Nov 30, 2023 · 2 comments
Open

Provide Twig Code Completion / Snippets #150

thomasfrobieter opened this issue Nov 30, 2023 · 2 comments
Assignees

Comments

@thomasfrobieter
Copy link
Contributor

thomasfrobieter commented Nov 30, 2023

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
Copy link
Member

JPustkuchen commented Nov 30, 2023

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants