Syntax highlighting, 110 snippets, hover documentation, and Pretty Diff formatting for Twig templates
Version 1, superseded by Twig Language 2. Install that instead unless you specifically want the HTML Intellisense this version adds.
ext install mblode.twig-languagePaste that into Quick Open (cmd+P), or search "Twig Language" in the Extensions panel. For the maintained version, install mblode.twig-language-2 instead.
Open a .twig file. Highlighting and hover apply straight away. Type a snippet prefix and press tab, so entries becomes:
{% for entry in craft.entries
.section("news")
.limit(10)
.all()
%}
<a href="{{ entry.url }}">{{ entry.title }}</a>
{% endfor %}110 of them, all in src/snippets/snippets.json:
- Twig tags:
if,for,block,embed,filter,macro,set,use,include,autoescape,verbatim, and every closing form. - Craft CMS queries:
entries,assets,categories,tags,users, andfeed, each with a loop body, pluscache,nav,paginate,switch, andredirect. - Forms:
formlogin,formuserregistration,formuserprofile,formforgotpassword,formsetpassword,formsearch, andformsearchresults, each a complete Craft form. - Helpers:
csrf,head,endbody, thecraft.app.requestgetters, and the maths filters (ceil,floor,round,min,max,random,shuffle).
Hold the cursor over Twig code to get its documentation: 33 filters, 15 functions, and 28 language constructs. Turn it off with twig-language.hover.
| Setting | Default | Description |
|---|---|---|
twig-language.hover |
true |
Show documentation for the Twig symbol under the cursor. |
twig-language.formatting |
true |
Register the Pretty Diff document formatter. |
twig-language.indentStyle |
tab |
Indent with tab or space. |
twig-language.quoteConvert |
none |
Convert attribute and string quotes to single or double. |
Another 35 Pretty Diff options sit under the same prefix, covering brace style, attribute indentation, comment handling, and wrap width.
- This version registers the
htmllanguage id with atwigalias, so it claims.twig,.html, and.html.twig. Twig Language 2 drops that, which is why it stops fighting VS Code over file associations. - Formatting runs on Pretty Diff 101.2.6, whose last upstream release was September 2019.
- Requires VS Code 1.30 or newer.
MIT
Crafted by Matthew Blode