Search code examples
phpcoding-stylephpstormlaravel-blade

How do I keep my indentation for the blade syntax in PHPStorm?


I am copying the following code from a *.blade.php file:

@section('content')
    <h1>All Users</h1>

    @if ($users->isEmpty())
        <h2>No Users Found</h2>
    @else
        @foreach ($users as $user)
            <li>{{ link_to("/users/{$user->username}", $user->username) }}</li>
        @endforeach
    @endif
@stop

This is how it appears when it is pasted into the same file:

@section('content')
    <h1>All Users</h1>

@if ($users->isEmpty())
        <h2>No Users Found</h2>
@else
@foreach ($users as $user)
            <li>{{ link_to("/users/{$user->username}", $user->username) }}</li>
@endforeach
@endif
@stop

I am assuming there is a code style somewhere that is removing the indents for the blade syntax, but I can't find which one. What setting do I need to change?


Solution

  • Generally speaking:

    Settings (Preferences on Mac) | Editor | Smart Keys | Reformat on Paste

    Why "generally" -- because there is no proper Blade support available in PhpStorm yet (but coming soon) and therefore no separate formatter rules for it. Because of that the aforementioned option most likely be the one responsible for such behaviour.