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

问题描述 投票:1回答:1

我正在试验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的限制吗?

php wordpress loops wordpress-theming blade
1个回答
1
投票

$loop变量将在@foreach()循环内部可用

@foreach ($users as $user)
    @if ($loop->first)
       // This is the first iteration.
    @endif
@endforeach
© www.soinside.com 2019 - 2024. All rights reserved.