PhpStorm provides native support for templates, and with version 2017.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 fragments between files.

See it for yourself! Invoke the actions search by pressing Shift+Command+A (Shift+Control+A on ) 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 choose 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 built 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

LEAVE A REPLY

Please enter your comment!
Please enter your name here