【问题标题】:Laravel blade @yield and @sectionLaravel 刀片 @yield 和 @section
【发布时间】:2017-11-18 21:32:22
【问题描述】:

在我的 main.blade.php 上

<div class="container">
     @yield('content')
</div>

在我的 home.blade.php 上

@extends('main')

    @section('content')
    <div class="row">
        <h1>this content should show on my main</h1>
    </div>
    @endsection

可能有什么问题,它没有在我的@section 上显示内容我没有错误,但它无法按照我使用 Laravel 5.4 的方式工作

【问题讨论】:

  • 主要的php在哪里?主刀片在哪里?
  • @exprator 它们都位于资源和视图文件夹内
  • 表示两者都在同一个目录中,对吗?比如 main.php,home.php?
  • 尝试使用@stop 而不是@endsection
  • @Exprator 是的,他们是

标签: php laravel templates layout blade


【解决方案1】:

确保你的 main.blade.php 和 home.blade.php 位于 resource/views/

如果它们位于不同的目录,使用“.”来指定目录

例如,如果 main.blade.php 在 resource/views/layouts 中,那么它将是这样的 @extends('layouts.main')

【讨论】:

  • 是的,它们都在视图文件夹内的资源中
  • 你得到的输出是什么
  • nothing 当我检查页面源时,应该显示在 main.blade.php 上的内容不包括在内
【解决方案2】:

我认为您需要更新 main.blade.php 的代码,例如:

<div class="container">
     @yield('content')
</div>

到

<section class="content">
     @yield('content')
</section>

希望这对你有用

【讨论】:

  • 我很惊讶。将div 更改为section 如何解决问题?
  • @Bhavik Shah nah 它没有
猜你喜欢
  • 2019-01-15
  • 2018-11-07
  • 1970-01-01
  • 2017-07-15
  • 2012-12-05
  • 2019-01-12
  • 1970-01-01
  • 2015-05-18
  • 2015-08-05
相关资源
最近更新 更多