我在 <section>
中有一个循环:
<section>
<h4 role="heading" aria-level="4">@lang('site.scope')</h4>
<ul>
@for( $i = 1; $i <= 4; $i++)
@if( $card->{"gen_champ__q" . $i } == 1 )
<li>@lang( 'questions-general.gen_champ_q' . $i . '_1' )</li>
@endif
@endfor
</ul>
</section>
,但是如果(== 1),我没有符合我状况的数据。因此,我想隐藏完整的部分。
但是我不知道该怎么做,你有一个主意吗?如果我在我的部分之上,它将复制我的内容,这不是我想要的。
您将用第一个&lt编写部分的"标题";li>(只有第一个)您必须写。并且您只有在任何&lt时才写入本节的"页脚";li>写了。
@for( $i = 1; $i <= 4; $i++)
@if( $card->{"gen_champ__q" . $i } == 1 )
@if (!isset($doSection) && $doSection=true)
<section>
<h4 role="heading" aria-level="4">@lang('site.scope')</h4>
<ul>
@endif
<li>@lang( 'questions-general.gen_champ_q' . $i . '_1' )</li>
@endif
@endfor
@if (isset($doSection))
</ul>
</section>
@endif
编辑:刚刚升级以避免不需要的变量初始化。
您可以在部分开始之前加一个。
@if($i>0)
<section>
<h4 role="heading" aria-level="4">@lang('site.scope')</h4>
<ul>
@for( $i = 1; $i <= 4; $i++)
@if( $card->{"gen_champ__q" . $i } == 1 )
<li>@lang( 'questions-general.gen_champ_q' . $i . '_1' )</li>
@endif
@endfor
</ul>
</section>
@endif
有很多方法是这样做。在您的病情相遇时,它就打印了其他不
@for( $i = 1,$j=1; $i <= 4; $i++)
@if( $card->{"gen_champ__q" . $i } == 1 )
@if($j==1&&$j--)
<section>
<h4 role="heading" aria-level="4">@lang('site.scope')</h4>
<ul>
@endif
<li>@lang( 'questions-general.gen_champ_q' . $i . '_1' )</li>
@endif
@endfor
@if($j==0)
</ul>
</section>
@endif
希望这对您有帮助!
@for( $i = 1; $i <= 4; $i++)
@if( ! empty( $card->{"gen_champ__q" . $i })
&& $card->{"gen_champ__q" . $i } == 1 )
<li>@lang( 'questions-general.gen_champ_q' . $i . '_1' )</li>
@endif
@endfor