我正在尝试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的限制吗?
答案 0 :(得分:1)
$loop
变量将在@foreach()
循环
@foreach ($users as $user)
@if ($loop->first)
// This is the first iteration.
@endif
@endforeach