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.4
  • github.​com
  • github.​com
  • 1 day ago
  • 13 minutes ago
  • 9 years ago

Installs

  • Total 100K
  • Win 43K
  • Mac 33K
  • Linux 24K
May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30 Apr 29 Apr 28 Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29
Windows 3 9 14 14 5 8 8 4 11 14 4 5 2 14 16 10 7 11 13 8 14 6 9 8 11 4 7 11 9 14 14 22 4 7 9 8 10 16 5 3 7 11 15 11 13 19
Mac 2 5 8 8 6 2 5 1 7 8 5 4 7 4 8 8 7 11 2 2 5 6 11 9 5 2 3 6 8 10 9 8 1 3 9 7 5 4 5 1 3 3 6 4 6 10
Linux 1 3 2 5 5 8 1 2 7 3 3 5 3 2 4 5 6 6 3 3 4 8 10 4 6 2 3 10 9 6 5 5 3 2 4 5 9 9 8 0 1 4 12 11 5 4

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 BetterTwig 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 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 #{|}.
  • Use backspace to come out of an empty expression/statement.

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

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 %}

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

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