Trouble parsing variable element name in Twig


In a fair few of my .twig templates, I use a pattern where I define a heading element tag into a variable and then use that variable as follows:

{% set headingLevel = headingLevel|default('h2') %}
<{{ headingElement }}>
Title goes here
</{{ headingElement}}>

However, PhpStorm does not recognize "<{{ headingElement }}>" as a valid opening tag, therefore causing file formatting problems as well as "closing tags not matching anything" warnings. The formatting problems are especially annoying however.

Is there any way I could make PhpStorm recognize this type of Twig usage as a valid opening tag for an element? Is there a plugin I could use or some IDE setting I could tweak to make this work?


Please sign in to leave a comment.