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

Twig

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

Labels Twig, templates, PHP, syntax

Details

Installs

  • Total 111K
  • Win 48K
  • Mac 37K
  • Linux 27K
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 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12
Windows 6 4 3 3 1 2 1 4 3 4 5 3 0 4 4 3 2 3 9 4 0 6 5 7 7 7 2 2 8 5 2 4 7 1 1 3 4 1 2 5 2 1 1 4 5 4
Mac 2 2 3 0 2 0 1 2 5 3 2 2 1 0 2 4 1 4 4 1 2 3 6 2 3 3 1 1 2 2 3 3 1 0 0 3 2 1 4 3 3 2 5 5 1 4
Linux 1 1 5 1 1 1 0 1 2 2 2 1 2 0 1 1 2 2 3 0 1 1 1 4 3 2 1 0 1 2 6 4 0 1 0 1 4 2 0 2 0 1 3 0 0 4

Readme

Source
raw.​githubusercontent.​com

Twig

LICENSE Sublime Text Tag Downloads Syntax tests

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,

  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 HTML (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 {{ | }}.
  • 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

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.

  • apply
  • autoescape
  • block
  • dump
  • embed
  • extends
  • for
  • if
  • if else
  • include
  • macro
  • sandbox
  • set
  • verbatim
  • with

If you want to ignore the snippets that are provided by default, you can use the ignored_snippets setting.

"ignored_snippets": ["Twig/*"]

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.