Solution:
This is currently a known limitation of Laravel Pint and its underlying Blade formatter (internally, Pint uses blade-formatter). Out of the box, neither Pint nor blade-formatter understands user-defined/custom block directives like @island and @placeholder as indentation scopes, so it "flattens" their contents.
Why This Happens
- Pint/blade-formatter only recognizes built-in Blade structural directives:
@if,@foreach,@section, etc. - Custom directives must be explicitly declared as block directives to the formatter for proper indentation.
Workaround / Solution
The good news: as of blade-formatter v2.5.0, custom block directive support exists via configuration!
Using Pint 1.5.x+ (and blade-formatter v2.5+ under the hood)
You can define a blade-formatter.json config file at your project root.
(If you're using Pint 1.5.x+, you can do this!)
Example: blade-formatter.json
{
"indentSize": 4,
"customBlockDirectives": [
"island",
"endisland",
"placeholder",
"endplaceholder"
]
}
However, you should only list opening block directives, not the end... close.
So usually:
{
"customBlockDirectives": [
"island",
"placeholder"
]
}
How to set up with Laravel Pint
-
Create
blade-formatter.jsonin your project root:{ "customBlockDirectives": [ "island", "placeholder" ] } -
Update Pint (if necessary) and run Pint:
composer update laravel/pintNow when you run Pint, it will pass the settings to the underlying blade-formatter.
If you use blade-formatter directly (CLI)
You can instead pass the directives as arguments:
blade-formatter --custom-block-directives "island,placeholder" resources/views/
Current Limitations
- In Pint 1.0 - 1.4.x, you cannot pass custom block directives—the feature was added to blade-formatter later. Upgrade Pint if possible.
- Only the opening directive name is needed; blade-formatter auto-matches
@end<directive>. - Not all nested custom directives work perfectly, but basic block-level nesting is supported.
Summary
No, there is not a way to do this out of the box. But you CAN configure custom block directives by creating a
blade-formatter.jsonin your project root and specifying them ascustomBlockDirectives. Pint 1.5+ passes this on to blade-formatter and your indentation will be fixed.
References:
- blade-formatter: customBlockDirectives
- Pint config file docs
- Pint issue: Custom block directive support
Example directory structure:
project-root/
├── blade-formatter.json
├── resources/
│ └── views/
│ └── analytics.blade.php
├── ...
After configuring, run:
vendor/bin/pint
And you should get correct indentation for your custom directives! 🎉
Let me know if this doesn't solve your case or if you need Pint to support this directly in its own config.