在Sage 9的观点中,Laravel Blade的$ loop vairable是否可用?

时间:2017-12-31 06:23:07

标签: php wordpress loops wordpress-theming blade

我正在尝试Sage WordPress启动主题的第9版,该主题使用Laravel Blade作为构建WP模板的模板引擎。

我的问题是: 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 个答案:

答案 0 :(得分:1)

$loop变量将在@foreach()循环

中提供
@foreach ($users as $user)
    @if ($loop->first)
       // This is the first iteration.
    @endif
@endforeach