dtp0760 2017-06-15 08:23
浏览 107

在@foreach循环中显示一个@section

Hi I'm new to laravel and can't understand sections very well, but I am trying to display a specific one in a loop only once and then repeat everything else, if a certain condition is true. Here is the code I'm trying to modify. Here i commented the line which i want only one time.

 @foreach ($pageTypes['news-events']->categories as $cat)
    <?php  $related = $page->relatedPages($pageTypes['news-events']->id, $cat->id); ?>
    @if ($related->count() > 0) 
        @section('tab-titles')
        //i want to display this LI once if true  
        <li class="tab first"><a href="#news" title="insight">Insight</a></li>
        @append
        @section('news-content')
            <div id="news" class="tabs_text">
                <h2>{{ strtoupper($cat->name) }} 
                </h2>
                <ul>
                @foreach($related as $news)
                    <li><a href="{{ url($news->url) }}" title="{{ $news->title }}">
                            {{ $news->title }}
                        </a>
                    </li>
                @endforeach
                </ul>
            </div>
        @append
    @endif
  @endforeach
  • 写回答

3条回答 默认 最新

  • douniang3866 2017-06-15 08:27
    关注

    You should use an else since you only want to display it once

    Check documentation here link

    @if ($related->count() > 0)
        @section('news-content')
            <div id="news" class="tabs_text">
                <h2>{{ strtoupper($cat->name) }} 
                </h2>
                <ul>
                @foreach($related as $news)
                    <li><a href="{{ url($news->url) }}" title="{{ $news->title }}">
                            {{ $news->title }}
                        </a>
                    </li>
                @endforeach
                </ul>
            </div>
        @append
    @else
        @section('tab-titles')
        //i want to display this LI once if true  
        <li class="tab first"><a href="#news" title="insight">Insight</a></li>
        @append
    @endif
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化