A Sublime Text package that offers enhanced syntax highlighting, snippets, completions and much more for PHP Twig templates. Read more for the full documentation.
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.
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".
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 to Open all with current extensions as ...
and scroll to select HTML (Twig)
. You should now be good to go.
When the currently open file is a .twig
file, 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"
]
}
{{ | }}
.{}
will add spaces on both sides of the inner %
like so {% | %}
{# This is a Twig comment #}
)#{|}
.This package adds basic snippets for common code blocks. If you want more snippets, then please follow the official documentation on snippets and 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": ["Twig/*"]
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.