【问题标题】:Why is my Blade template content displayed twice?为什么我的 Blade 模板内容显示两次?
【发布时间】:2013-06-21 11:18:06
【问题描述】:

我的刀片模板有问题。出于某种原因,我将视图的内容打印了两次,一次是我期望的yield,另一次是在扩展的视图执行任何操作之前。

我的路线是:

Route::get('/', array('as' => 'home', function () {
    return View::make('default');
}));

默认视图 (default.blade.php) 是这样的:

@extends('test')

@section('title')
    Default
@show

@section('content')
    <p>Content goes here<p>
@show

测试视图(test.blade.php)是这样的:

<h1>Anything above should be be there!</h1>
<h3>@yield('title')</h3>
@yield('content')

这会产生:

Default
<p>Content goes here<p>
<h1>Anything above should be be there!</h1>
<h3>Default</h3>
<p>Content goes here<p>

【问题讨论】:

    标签: php templates laravel laravel-4 blade


    【解决方案1】:

    这不应该是...@stop 而不是@show

    @extends('test')
    
    @section('title')
    Default
    @stop
    
    @section('content')
    <p>Content goes here<p>
    @stop
    

    【讨论】:

      【解决方案2】:

      试试

      @extends('test')
      
      @section('title')
          Default
      @stop
      
      @section('content')
          <p>Content goes here<p>
      @stop
      

      【讨论】:

      • 啊,我没听懂 show 和 stop 的区别。谢谢!
      • 想解释一下“show”和“stop”的区别吗?
      • 如果你使用@show,Laravel 假定这是你的默认值,可以被另一个@section('content') 覆盖。
      猜你喜欢
      • 1970-01-01
      • 2017-11-21
      • 2017-01-26
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      相关资源
      最近更新 更多