【发布时间】:2016-01-22 13:30:16
【问题描述】:
当我包含一个扩展基本刀片的刀片模板时,包含刀片部分中的任何变量都只显示第一次迭代的变量。
仔细阅读,这里的渲染顺序似乎很重要,视图在变量之前渲染,反之亦然。
注意
- 我已阅读此 SO 问题/答案:Laravel Blade @yield variable scope
- 以下 sn-p 的复杂性大大降低,因此可以重新构建示例以排除节/扩展。但是我的真实情况不可能
示例
// index.blade.php
//
@foreach($jobs as $job)
{{ $job->id }} // <-- Correct output, 1,2,3,..N
@include('job-detail', ['id' => $job->id])
@endforeach
然后在作业详细信息刀片中
// job-detail.blade.php
//
@extends('job-base')
A: {{ $id }} // <-- Correct output, 1,2,3,..N
@section('content')
B: {{ $id }} // <-- Incorrect output, 1,1,1,..1 (or whatever the first index is)
@endsection // have also tried @stop
然后在作业基础刀片中
// job-base.blade.php
//
@yield('content') // Have also tried @section('content') + @show
【问题讨论】:
标签: php laravel laravel-5 laravel-5.1