- Twig
- Syntax Highlighting and Completions for Twig (and Craft CMS) Template Files (.twig)
- 7958 Installs
Readme
Twig for Nova
This extension for Nova, a text editor from Panic, adds syntax highlighting for Twig, a popular templating language. It supports all relevant language features from Twig 3.0+ and even some custom tags/filters from Craft CMS 3.0+.
This extension also includes a huge list of completions for Twig and Craft CMS 3.0+, including Element Queries.
Installation
In Nova, go to “Extension > Extensions Library”, search for “Twig” and install the extension.
Manual way: Download this repository, extract the .zip file and open the folder with Nova.
If you use Twig inside Markdown files (e.g. Grav CMS): Map “.md” to “Twig-Markdown” in settings to activate syntax highlighting for Twig inside regular Markdown files.
Development
Clone this repository and open the folder with Nova. In Nova, go to “Settings > General” and enable “Show extension development items in the Extension menu”. Then activate the extension via the “Extension” menu.
Ideas for future development
- [ ] Migrate all syntax definitions and completions to Tree-sitter (Nova 10+)
- [ ] Update completions for Craft 4+
- [ ] Add support for matching Twig brackets (not possible at the moment?)
If you have some tips or want to help with development, feel free to let me know!
Changelog
Version 1.8.2
- Fix: Re-add support for HTML completions for compatibility with Nova 10+.
Version 1.8.1
- Add support for modifiers (e.g.
at head
) on fenced code blocks ({% css %}
and{% js %}
)
Version 1.8
- Add support for nested syntax highlighting inside
{% css %}
and{% js %}
(Craft CMS)
Version 1.7
- Add optional
Twig-Markdown
syntax definition: Map “.md” to “Twig-Markdown” in settings to activate syntax highlighting for Twig inside Markdown files (Grav CMS).
Version 1.6
- Add completions for Craft Element Queries and common properties
Version 1.5
- Add completions without closing tags
- Fix: Don’t show completions right before
%}
Version 1.4.1
- Fix: Don’t show syntax highlighting inside comments
Version 1.4
- Add symbols for macro definitions
- Add completions for variables and macros defined in the same file
- Add completions for argument lists
Version 1.3
- Add basic tag completions for Twig-HTML (outside opening brackets)
- Fix: correct end tag for
autoescape
completion - Fix: correct syntax highlighting for blocks and variables named like keywords
Version 1.2
- Auto insert
%}
after tags in completions - Auto insert
{% endif %}
,{% endfor %}
etc. in tag completions - Auto insert space after function calls in completions
- Improve context for completions
- Remove matching
{}
from Twig-HTML syntax
Version 1.1
- Completions for Craft CMS 3.0+
- Better Syntax Highlighting for Craft CMS 3.0+
- Better Icon
Version 1.0
Initial release
- Syntax Highlighting for Twig 3.0+
- Syntax Highlighting for custom tags/filters from Craft CMS 3.0+
- Completions for Twig 3.0+
License
MIT License
Copyright (c) 2023
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.