Radmation Radmation - 2 months ago 4
CSS Question

PhpStorm thinks <div> is open but it isn't with blade directives

Here is the code:

@if (count($errors) > 0)
<div class="errorClass">
@else
<div class="cleanClass">
@endif
<p>Some stuff</p>
</div>


The above code make PhpStorm register that there is an open
<div>
. Any way to fix this bug?

This is making it frustrating to use when it comes time to refactor code.

I installed the Blade extension hoping that would help - it didn't. PhpStorm reports:


Element div is not closed.


Any way to make PhpStorm smarter?

Answer

(Posted on behalf of the OP).

Workaround

This works but is not easy to read.

<div
    @if (count($errors) > 0)
         class="errorClass"
    @else
         class="cleanClass"
    @endif
>
    <p>Here is a paragraph</p>
</div>

Best Situation for readability

@if (count($errors) > 0)
    <?php  $class = 'class="errorClass"' ?>
@else
    <?php $class = 'class="cleanClass"'  ?>
@endif
<div <?= $class; ?>>
    <p>Blah blah</p>
</div>