2017-12-31 66 views
1

WPテンプレートを構築するためのテンプレートエンジンとしてLaravel Bladeを使用しているSage WordPressスターターテーマのバージョン9を試しています。

私の質問はです。Sage 9はBlade's $loop variableをループ内で利用できますか?

例えば、与えられたファイル/my_theme/resources/views/archive.blade.php

1 @extends('layouts.app') 
2 
3 @section('content') 
4  @include('partials.page-header') 
5 
6  @if (!have_posts()) 
7  <div class="alert alert-warning"> 
8   {{ __('Sorry, no results were found.', 'sage') }} 
9  </div> 
10  {!! get_search_form(false) !!} 
11  @endif 
12 
13  @while (have_posts()) @php(the_post()) 
14 
15  @include('partials.content-'.get_post_type()) 
16  @endwhile 
17 
18  {!! get_the_posts_navigation() !!} 
19 @endsection 

私は14行で次のように挿入したいと思います:

@if ($loop->first) 
    // Do stuff on first iteration 
@endif 

しかし$loopは未定義です。

私は何かが紛失していますか、これは現在のSage 9の制限ですか?

答えて

1

$loop変数は@foreach()ループ

@foreach ($users as $user) 
    @if ($loop->first) 
     // This is the first iteration. 
    @endif 
@endforeach 
の内部に利用できるようになります
関連する問題