phpphpstormjetbrains-idecode-folding

How to enable code folding with conditional blocks in PhpStorm (JetBrains)?


I was wondering if there is a way to enable PhpStorm (or any other JetBrains tool that deals with .phtml files) to recognize conditional blocks when collapsing units of code.

I have this example:

<div class="parent">
    <?php if (condition) : ?>
        <div class="div1">
    <?php elseif (conditionTwo) : ?>
        <div class="div2">
    <?php endif; ?>

    <!-- Conditional block ends here -->
    </div>

<!-- Parent container ends here -->
</div>

PhpStorm (by default) allows me to collapse div2 (with the first </div>), therefore div1 will need to collapse with the last </div>, which is meant to be collapse with parent.

I have attempted to adjust settings, but with no success.

Microsoft's Visual Studio Code has the correct behavior: VSCode correct collapse behavior

As you can see, in VSCode you are not allowed to collapse on <div>'s that are inside the php if block.

Thanks for your time.


Solution

  • This can't be configured with given code sample. You can submit this to JetBrains tracker at https://youtrack.jetbrains.com/newIssue for developers to look into it & address in next IDE versions.