Jinja2
A Sublime Text package that provides enhanced syntax highlighting, completions, snippets & more for Jinja templates.
Details
Installs
- Total 76K
- Win 21K
- Mac 32K
- Linux 23K
Sep 28 | Sep 27 | Sep 26 | Sep 25 | Sep 24 | Sep 23 | Sep 22 | Sep 21 | Sep 20 | Sep 19 | Sep 18 | Sep 17 | Sep 16 | Sep 15 | Sep 14 | Sep 13 | Sep 12 | Sep 11 | Sep 10 | Sep 9 | Sep 8 | Sep 7 | Sep 6 | Sep 5 | Sep 4 | Sep 3 | Sep 2 | Sep 1 | Aug 31 | Aug 30 | Aug 29 | Aug 28 | Aug 27 | Aug 26 | Aug 25 | Aug 24 | Aug 23 | Aug 22 | Aug 21 | Aug 20 | Aug 19 | Aug 18 | Aug 17 | Aug 16 | Aug 15 | Aug 14 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 0 | 4 | 2 | 3 | 0 | 0 | 7 | 3 | 1 | 7 | 1 | 1 | 2 | 4 | 6 | 2 | 5 | 0 | 0 | 1 | 2 | 9 | 0 | 4 | 1 | 1 | 2 | 1 | 7 | 6 | 4 | 5 | 3 | 0 | 0 | 6 | 1 | 5 | 6 | 0 | 0 | 3 | 1 | 3 | 2 | 4 |
Mac | 1 | 1 | 5 | 2 | 1 | 3 | 3 | 3 | 4 | 7 | 3 | 2 | 0 | 2 | 4 | 6 | 2 | 4 | 1 | 1 | 1 | 0 | 2 | 7 | 3 | 2 | 3 | 4 | 0 | 6 | 2 | 2 | 2 | 0 | 4 | 4 | 3 | 5 | 4 | 0 | 0 | 3 | 4 | 2 | 5 | 5 |
Linux | 0 | 2 | 4 | 4 | 7 | 1 | 4 | 1 | 2 | 3 | 1 | 0 | 3 | 2 | 2 | 3 | 4 | 0 | 2 | 2 | 2 | 2 | 0 | 2 | 4 | 2 | 0 | 3 | 3 | 3 | 5 | 4 | 0 | 1 | 1 | 3 | 5 | 4 | 2 | 3 | 0 | 2 | 11 | 0 | 3 | 4 |
Readme
- Source
- raw.githubusercontent.com
BetterJinja
A Sublime Text package that offers enhanced syntax highlighting, snippets, completions and much more for Jinja templates. Read more for the full documentation.
Features
- Indentation for code blocks.
- Snippets for common code blocks.
- Key bindings to make your life easier.
- Enhanced syntax highlighting for Jinja templates.
- Autocompletions for built in tags, filters, functions, tests & loop variables.
Installation
Package Control
The best way is to install it via Package Control. Once you have Package Control setup in Sublime Text, open the command palette and search for Package Control: Install Package
. Search for BetterJinja
and install it. Package Control will take care for of automatically updating the package for you if there are new releases.
You can also use Package Control: Add Repository
. Copy the github url (without the .git
at the end) and enter it into the input panel that pops up at the bottom when you select Package Control: Add Repository
. Now use Package Control: Install Package
and search for BetterJinja
and install it.
Documentation
How to use this package ?
By default, this package supports the following Jinja extensions:
j2
, jinja
, jinja2
, html.j2
, html.jinja
, html.jinja2
, htm.j2
, htm.jinja
, htm.jinja2
.
Since a user can have more than one templating language package installed, this package doesn't support .html
directly. To get highlighting for .html
files with Jinja code and all the other features this package provides, you can follow any of the two approaches given below
Go to the bottom right status bar item that displays information on current syntax and click on that when the currently open file is any
.html
file. From there go toOpen all with current extensions as ...
and scroll to selectJinja
. You should now be good to go.When the currently open file has any of the aforementioned file extensions, from the main menu, go to
Preferences -> Settings -- Syntax Specific
. This should open a 2 column new window, with the default settings on the right and a user settings on the left. In the user settings, add the following, save & close.
{
"extensions": [
".html"
]
}
Key bindings
- The key bindings are configured so that pressing shift + { twice will automatically add spaces on both sides for the inner brace expression block & place the cursor in the center, like so
{{ | }}
. - |||ly pressing shift + % within
{}
will add spaces on both sides of the inner%
like so{% | %}
- You can use ctrl + / for inserting Jinja style line comments (
## This is a line comment
) - Similarly, use ctrl + shift + / for block style comments (
{# This is a block comment #}
)
Auto completions
In order to get the auto completions, go to Preferences: Settings
from the command palette and paste the following in the Preferences.sublime-settings -- User
(the right hand window)
"auto_complete_selector": "text.jinja, meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",
"auto_complete_triggers":
[
{"characters": "<", "selector": "text.html"},
{"selector": "text.jinja, text.html.basic"},
]
If you already have these in your user settings, then just copy the Twig related portions into them.
Snippets
BetterJinja
only adds basic snippets for common code blocks. If you want more snippets, then please follow the official documentation on
snippets and create your own.
Tab Trigger | Jinja Code Block |
---|---|
jwith |
{% with %}{% endwith %} |
jraw |
{% raw %}{% endraw %} |
jmacro |
{% macro %}{% endmacro %} |
jifelse |
{% if %}{% else %}{% endif %} |
jif |
{% if %}{% endif %} |
jfor |
{% for %}{% endfor %} |
jfilter |
{% filter %}{% endfilter %} |
jextends |
{% extends %} |
jexp |
{% %} |
jcall |
{% call %}{% endcall %} |
jblock |
{% block %}{% endblock %} |
jautoescape |
{% autoescape %}{% endautoescape %} |
If you want to ignore the snippets that are provided by default, you can use the ignored_snippets
setting.
"ignored_snippets": ["BetterJinja/*"]
Issues & Feature requests.
There is always scope for improvements so please do report any bug(s) that you encounter or request for feature(s) that this package should support.
Please follow the issue & feature request templates that have been setup while reporting any bug(s) or requesting for feature(s) (So as to stay as organised as possible).
Acknowledgements.
The syntax_test.yml is taken & used (with some modifications) from the official Packages repository. So full credit goes to them for it.
License
The MIT License (MIT)
Copyright 2020-2022 © Ashwin Shenoy
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.