我正在试验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的限制吗?
$loop
变量将在@foreach()
循环内部可用
@foreach ($users as $user)
@if ($loop->first)
// This is the first iteration.
@endif
@endforeach