Laravel Blade without extra whitespace?
问题 If you do this you get an error: <p>@if($foo)@if($bar)test@endif@endif</p> And if you do this, you get <p> test </p> , adding too much whitepace: <p>@if($foo) @if($bar)test@endif @endif</p> Is there a way to avoid this? Edit: see my answer below for an updated response. There's a clean way to do this with no hacks or external libraries. 回答1: Try with a ternary operator, there is no whitespace control in Laravel <p>{{ $foo ? ($bar ? 'test' : '') : ''}}</p> 回答2: You could always use the