1

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.

dan1st
  • 12,568
  • 8
  • 34
  • 67
bem22
  • 276
  • 1
  • 14

2 Answers2

2

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.

Dmitrii
  • 3,377
  • 1
  • 21
  • 38
1

Really, the issue here is how you're writing the code. It would be cleaner (and remove the edge case of not having a final else if you did something like

<div class="<?= condition ? 'div1' : 'div2'; ?>">
Mez
  • 24,430
  • 14
  • 71
  • 93