I want to know how can I have highlighting syntax for TWIG in Sublime Text.
Actually when I open a TWIG file all fonctions and conditions are similar (white on black) :
4 Answers
Documentation
Syntax highlighting and auto-completion for Twig in Sublime Text 2
is possible with : PHP-Twig.tmbundle
- TWIG Doc "IDEs Integration" : http://twig.sensiolabs.org/doc/templates.html#ides-integration
- Bundle's Github : https://github.com/Anomareh/PHP-Twig.tmbundle
- Bundle's Documentation : https://sublime.wbond.net/packages/PHP-Twig
Download
You can clone the project with :
git clone https://github.com/Anomareh/PHP-Twig.tmbundle.git
Or download it directly from the Github (last master version) :
https://github.com/Anomareh/PHP-Twig.tmbundle/archive/master.zip
Installation
To install this bundle in Sublime Text, a few extra steps are required.
- Open Sublime Text and in the Preferences menu click Browse Packages.
- In the directory that was just opened, create a new directory
PHP-Twig/
. - Copy the content of this repo into the directory you just created.
- Move the contents of the
PHP-Twig/Syntaxes/
directory toPHP-Twig/
- Restart Sublime Text.
Apply
To apply syntax highlighting on your Twig HTML files :
- Open a
.html.twig
file - Go to View menu → Syntax → Open all with current extension as → HTML (Twig)
That’s it. It should work by now.
Happy Coding!
Screenshot
-
7This solution still works well on Sublime Text 3. In case, someone is looking solution for ST3.– SithuAug 30, 2015 at 7:08
-
-
I only needed to copy the package file
PHP-Twig.tmbundle
into the packages directory for Sublime Text 3.– HenrikMay 22, 2017 at 14:50 -
1I cant find the apply section in the github. Thanks god this answer provides Jul 22, 2019 at 6:54
You can also install PHP-Twig.tmbundle through Sublime Text's Package Control.
With Package Control installed:
- Go to Preferences → Package Control → Install Package
- Type "Twig", and select PHP-Twig.
It will install the same version of @antoine-subit's answer, and will automatically use the correct syntax for any Twig file you open
-
1
If you're not used to Sublime, don't forget to click on the bottom right of the sublime window (a drop up/down should appear) and then select "HTML (Twig)" from the list of languages in order to enable the package!
-
1Thanks, Mr. @user2511803 ! I was searching for Twig, instead of HTML (Twig). Fistbump. Sep 27, 2016 at 14:58
-
Installed this, uninstalled it, and then reinstalled after reading this comment. Should be mentioned in the docs. Feb 4, 2018 at 7:24
I'm working on Ubuntu, I have solved the problem by downloading https://github.com/Anomareh/PHP-Twig.tmbundle/archive/master.zip and I have done what was wrote inside ReadMe file.
- After restarting Sublime Text choose the option called “HTML (Twig)” in “View->Syntax” menu to see the new highlighting.
- To automatically highlight all twig files, open any html.twig template and select “View->Syntax->Open all current extension as…->HTML (Twig)”