Twig
A Sublime Text package that provides enhanced syntax highlighting, completions, snippets & more for PHP Twig templates.
Details
Installs
- Total 201K
- Win 86K
- Mac 67K
- Linux 49K
Nov 21 | Nov 20 | Nov 19 | Nov 18 | Nov 17 | Nov 16 | Nov 15 | Nov 14 | Nov 13 | Nov 12 | Nov 11 | Nov 10 | Nov 9 | Nov 8 | Nov 7 | Nov 6 | Nov 5 | Nov 4 | Nov 3 | Nov 2 | Nov 1 | Oct 31 | Oct 30 | Oct 29 | Oct 28 | Oct 27 | Oct 26 | Oct 25 | Oct 24 | Oct 23 | Oct 22 | Oct 21 | Oct 20 | Oct 19 | Oct 18 | Oct 17 | Oct 16 | Oct 15 | Oct 14 | Oct 13 | Oct 12 | Oct 11 | Oct 10 | Oct 9 | Oct 8 | Oct 7 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 6 | 3 | 0 | 2 | 1 | 9 | 0 | 0 | 0 | 3 | 3 | 0 | 2 | 6 | 2 | 2 | 2 | 2 | 2 | 2 | 3 | 2 | 2 | 5 | 2 | 0 | 4 | 1 | 5 | 2 | 5 | 5 | 3 | 1 | 0 | 3 | 1 | 2 | 1 | 0 | 2 | 1 | 3 | 1 | 2 | 3 |
Mac | 1 | 1 | 2 | 1 | 0 | 2 | 7 | 0 | 0 | 5 | 4 | 1 | 1 | 4 | 1 | 4 | 3 | 0 | 0 | 4 | 2 | 2 | 2 | 2 | 3 | 1 | 0 | 2 | 2 | 2 | 1 | 5 | 0 | 0 | 0 | 4 | 3 | 3 | 1 | 1 | 0 | 2 | 2 | 1 | 2 | 2 |
Linux | 0 | 2 | 0 | 0 | 3 | 0 | 2 | 0 | 0 | 2 | 2 | 0 | 0 | 0 | 2 | 1 | 2 | 5 | 0 | 1 | 2 | 2 | 2 | 5 | 2 | 2 | 2 | 4 | 0 | 2 | 5 | 0 | 0 | 1 | 3 | 1 | 2 | 1 | 0 | 3 | 5 | 2 | 2 | 1 | 1 | 1 |
Readme
- Source
- raw.githubusercontent.com
Twig
A Sublime Text package that offers enhanced syntax highlighting, snippets, completions and much more for PHP Twig 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 Twig templates.
- Autocompletions for built in tags, filters, functions, tests & loop variables.
Installation
Package Control
Install Twig 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 Twig
. There should be a package with the URL as https://github.com/Sublime-Instincts/BetterTwig. Install it.
Package Control will take care for of automatically updating the package for you if there are new releases.
Manual installation
In Sublime Text open the Preferences > Browse Packages menu item. In the Packages directory you should now see, clone this repository in a new directory called “Twig”.
Documentation
How to use this package ?
By default, this package supports the following Twig extensions,
.twig
.htm.twig
.html.twig
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 Twig 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 selectHTML (Twig)
. You should now be good to go.When the currently open file is a
.twig
file, from the main menu, go toPreferences -> 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
{{ | }}
. - Similarly, pressing shift + % within
{}
will add spaces on both sides of the inner%
like so{% | %}
- Use ctrl + / or ctrl + shift + / for Twig comments (
{# This is a Twig comment #}
) - Use # within strings, to get the interpolation expression, like so
#{|}
.
Snippets
Basic snippets for each keyword are provided to create expressions without bothering with {% %}
.
Tab Trigger | Twig Tag |
---|---|
autoescape |
{% autoescape %} |
endautoescape |
{% endautoescape %} |
… | … |
Prefixed with b
basic snippets for most common control structures are provided.
Tab Trigger | Twig Code Block |
---|---|
bautoescape |
{% autoescape %}{% endautoescape %} |
bblock |
{% block %}{% endblock %} |
bembed |
{% embed %}{% endembed %} |
bextends |
{% extends %} |
bfor |
{% for %}{% endfor %} |
bif |
{% if %}{% endif %} |
bifelse |
{% if %}{% else %}{% endif %} |
bmacro |
{% macro %}{% endmacro %} |
bsandbox |
{% sandbox %}{% endsandbox %} |
bverbatim |
{% verbatim %}{% endverbatim %} |
bwith |
{% with %}{% endwith %} |
For more, please follow the official documentation on snippets to create your own.
Or use SnippetMaker for convenience.
If you want to ignore the snippets that are provided by default, you can use the ignored_snippets
setting.
ignored snippets | values |
---|---|
all | "Twig/Snippets/*" |
blocks | "Twig/Snippets/blocks" |
expressions | "Twig/Snippets/expressions" |
tags | "Twig/Snippets/tags" |
Example
To only keep tag snippets…
{
"ignored_snippets": [
"Twig/Snippets/blocks",
"Twig/Snippets/expressions",
],
}
Reporting issues.
There is always scope for improvements, so please do report any bug(s) that you encounter.
Please follow the issue template that has been setup while reporting any bug(s) (So as to stay as organised as possible).
Use the Twig playground if you want to share a particular snippet of template while creating a specific issue.