在这种情况下,如何使用 child 隐藏 <section>
How to hide <section> with a child for in this case
我在 <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>
但是我没有满足我条件的数据if (== 1)。
所以,我想隐藏完整的部分。
但是我不知道怎么做,你有什么想法吗?如果我超出我的部分,它会复制我的内容,这不是我想要的。
@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
如果在章节开始之前,您可以多放一个。
@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
有很多方法可以做到这一点,其中之一就是这个。
在这种情况下,当您的条件满足时,它会打印 else not
@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
希望对您有所帮助!
您将在本节的 "header" 中写下您必须写的第一个 < li> (并且只有第一个)。并且只有在写入任何
时,您才会写入该部分的 "footer"。
@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
编辑:刚刚升级以避免不必要的变量初始化。
我在 <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>
但是我没有满足我条件的数据if (== 1)。 所以,我想隐藏完整的部分。
但是我不知道怎么做,你有什么想法吗?如果我超出我的部分,它会复制我的内容,这不是我想要的。
@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
如果在章节开始之前,您可以多放一个。
@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
有很多方法可以做到这一点,其中之一就是这个。 在这种情况下,当您的条件满足时,它会打印 else not
@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
希望对您有所帮助!
您将在本节的 "header" 中写下您必须写的第一个 < 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
编辑:刚刚升级以避免不必要的变量初始化。