Skip to end of metadata
Go to start of metadata

Redirection Notice

Icon
This page will redirect to https://www.jetbrains.com/help/phpstorm/symfony-twig.html in about 2 seconds.

 

Twig Templates

The Symfony2 Plugin comes with a number of completion, navigation and inspections specific to the Twig templating language. We've already seen a number of these features in the Working with Templates section, but there are a couple more things.

Completion and Navigation for Templates and Blocks

In any .twig file, we can get completion for Templates and Blocks for appropriate functions by pressing (Ctrl+Space).


When hovering over a Template or Block name, we can Ctrl+Click (or CMD+Click on Mac OS X) to navigate to its declaration. Pressing Ctrl+B (or CMD+B on Mac OS X) when the cursor is on them works as well.

Completion and Navigation for Extensions, Filters and Macros

While working on a Twig template, PhpStorm will offer completion and navigation for Extensions, Filters and Macros, whether we define them or they are defined and installed from a third party. Completion can be invoked by pressing Ctrl+Space.

We can Ctrl+Click (or CMD+Click on Mac OS X) a usage of an Extension, Filter or Macro to navigate to its declaration. This can also be achieved by placing the cursor on a usage and pressing Ctrl+B (or CMD+B on Mac OS X).

Completion, Navigation and Inspections for Assets

PhpStorm offers completion and navigation for individual assets and full bundles when pressing (Ctrl+Space).

We can Ctrl+Click (or CMD+Click on Mac OS X) a usage of an asset to navigate to it. Placing the cursor on one and pressing Ctrl+B (or CMD+B on Mac OS X) will do the trick, too.

If we refer an asset that is not known to the application, for example because it does not exist yet or if we made a typo in its path, PhpStorm will inform us about this through an inspection.

Completion, Navigation and Inspections for Translations

Completion, Navigation and Inspections for Translations are covered under the Working with Translations section.

Completion, Navigation and Inspections for Routes

Completion, Navigation and Inspections for Routes are covered under the Working with Routes section.

Working with Variables

In our Twig templates, we can define variables using the {# variable_name variable_value #} syntax, for example:

When defining a variable, we get completion (Ctrl+Space) and navigation (Ctrl+B (or CMD+B on Mac OS X)).

We could also define the controller that uses the template by adding a controller annotation, for example:

Once we do this, PhpStorm will provide completion (Ctrl+Space) and navigation (Ctrl+B (or CMD+B on Mac OS X)) for all variables passed into our template.

 

  • No labels