个性化阅读
专注于IT技术分析

Laravel Blade的$loop变量在Sage 9视图中可用吗?

点击下载

我正在试验Sage WordPress入门主题的版本9, 该主题使用Laravel Blade作为构建WP模板的模板引擎。

我的问题是:Sage 9是否使Blade的$ loop变量在视图的循环内可用?

例如, 给定文件/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
赞(0)
未经允许不得转载:srcmini » Laravel Blade的$loop变量在Sage 9视图中可用吗?

评论 抢沙发

评论前必须登录!