ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Twig

A Sublime Text Package that provides syntax highlighting, completions, snippets & more for PHP Twig templates.

Labels Twig, templates, PHP, syntax

Details

  • 2012.01.20.08.54.14
    1.0.6
  • github.​com
  • github.​com
  • 1 month ago
  • 2 hours ago
  • 10 years ago

Installs

  • Total 103K
  • Win 44K
  • Mac 34K
  • Linux 25K
Nov 30 Nov 29 Nov 28 Nov 27 Nov 26 Nov 25 Nov 24 Nov 23 Nov 22 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
Windows 5 8 2 5 7 12 7 6 11 6 2 9 10 7 10 11 6 6 9 6 9 9 8 5 3 10 11 12 11 9 3 5 16 6 16 13 10 5 4 8 6 11 10 15 6 6
Mac 3 6 2 1 7 5 10 6 6 1 0 5 9 9 6 12 5 2 14 8 6 10 13 3 3 12 8 7 8 7 4 2 5 6 5 9 7 1 0 4 6 9 5 4 2 3
Linux 1 3 3 2 2 8 4 4 5 3 2 0 5 4 6 1 1 1 6 5 6 4 5 2 6 4 1 5 2 2 2 4 5 6 6 2 6 1 3 7 6 2 2 4 1 2

Readme

Source
raw.​githubusercontent.​com

BetterTwig

LICENSE LICENSE Tag Downloads

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

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 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.

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 BetterTwig and install it.

Documentation

How to use this package ?

By default, this package supports the following Twig extensions,

  1. .twig
  2. .htm.twig
  3. .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

  1. 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 Twig. You should now be good to go.

  2. 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"
]

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 {% | %}
  • Use ctrl + / or ctrl + shift + / for Twig comments ({# This is a Twig comment #})
  • Use # within strings, to get the interpolation expression, like so #{|}.

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.html.twig, 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.html.twig, text.html.basic"},
]

If you already have these in your user settings, then just copy the Twig related portions into them.

Snippets

BetterTwig only adds basic snippets for common code blocks. If you want more snippets, then you can follow the official documentation on snippets and create your own.

Tab Trigger Twig Code Block
tapply {% apply %}{% endapply %}
tautoescape {% autoescape %}{% endautoescape %}
tblock {% block %}{% endblock %}
tdeprecated {% deprecated %}
tembed {% embed %}{% endembed %}
textends {% extends %}
tfor {% for %}{% endfor %}
tforelse {% for %}{% else %}{% endfor %}
tmacro {% macro %}{% endmacro %}
tsandbox {% sandbox %}{% endsandbox %}
tset {% set %}
tverbatim {% verbatim %}{% endverbatim %}
twith {% with %}{% endwith %}

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.

License

The MIT License (MIT)

Copyright 2021 © 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.