PhpStorm provides native support for templates, and with version 17.3 it just got better.

The Twig formatting mechanism now handles complex structures properly. It provides correct indentation for your code blocks and preserves it when copying and pasting code between files.

See it for yourself! Invoke the actions search by pressing Shift+Command+A (Shift+Control+A on Windows) and search for the Reformat code action:

reformat twig handling improvements - reformat - Twig handling improvements

We’ve also implemented the long-awaited language injections for Twig templates. To try them out, place the caret inside an opening {% block %} tag and invoke the Inject language or reference intention action by pressing Alt+Enter. Then, simply the desired language from the list and start writing your code:

injection_basic twig handling improvements - injection basic - Twig handling improvements

Language injection can also occur automatically when an injection rule is triggered. Two Twig-related injection rules are into PhpStorm 2017.3, which allow you to inject JavaScript code.

The first rule is triggered as soon as you name a block javascript:

injection_named_block twig handling improvements - injection named block - Twig handling improvements

And the second one – inside a custom script tag:

injection_custom_block twig handling improvements - injection custom block - Twig handling improvements

It doesn’t just stop here, of course. If you navigate to Settings | Editor | Language Injections, you’ll be able to customize these injections to your liking as well as create new ones. You can learn more about working with code injections in our help article.

Your JetBrains PhpStorm Team
The Drive to Develop

Source link


Please enter your comment!
Please enter your name here