如果执行此操作,则会出现错误:
<p>@if($foo)@if($bar)test@endif@endif</p>
如果你这样做,你会得到<p> test </p>
,增加了太多的空格:
<p>@if($foo) @if($bar)test@endif @endif</p>
Is there a way to avoid this?
如果执行此操作,则会出现错误:
<p>@if($foo)@if($bar)test@endif@endif</p>
如果你这样做,你会得到<p> test </p>
,增加了太多的空格:
<p>@if($foo) @if($bar)test@endif @endif</p>
Is there a way to avoid this?
这似乎获得了大量的搜索流量,所以我想我应该添加一个更新来分享我最近如何处理这个问题.基本上,这是一个多一点的代码,但它最终是愚蠢的简单和非常干净:
@if($foo)
<p>Test</p>
@elseif($bar)
<p>Test2</p>
@else
<p>Test3</p>
@endif
The moral of the story is when you're working with blade, don't try to cram a lot of conditionals within elements. Rather, have the result of the conditional contain the element. It's clean, easy to read, and with only a few more characters spent.