【问题标题】:Laravel: View not showing up html dataLaravel:查看未显示 html 数据
【发布时间】:2019-04-02 01:35:28
【问题描述】:
@extends('layouts.dashboard')
@section('content')
<h1>Its working</h1>
@stop

因此“它的工作”没有出现在浏览器上。刀片正在执行,但不是 html。

【问题讨论】:

标签: html laravel laravel-blade


【解决方案1】:

使用@endsection 而不是@stop

@extends('layouts.dashboard')

@section('content')
    <h1>Its working</h1>
@endsection

【讨论】:

【解决方案2】:

您需要添加@endsection 而不是@stop

@extends('layouts.dashboard')
@section('content')
    <h1>Its working</h1>
@endsection

在刀片文件中,可以添加多个@section标签,这就是为什么你必须添加@endsection

【讨论】:

    【解决方案3】:

    @extends 它允许您将一个文件的内容包含到另一个文件中

    @section 指令,顾名思义,定义了一段内容

    @extends('layouts.dashboard')
    @section('content')
        <h1>Its working</h1>
    @endsection
    

    阅读更多关于@extends here


    你也可以这样使用:

    @extends('layouts.dashboard')
    @section('content')
        <h1>Its working</h1>
    @stop
    

    它没有被弃用,您可以使用@stop 或@endsection,两者都可以正常工作。 (我检查了 Laravel5.7 并且它正在工作)

    @stop 和@endsection 的区别你可以看here

    【讨论】:

      【解决方案4】:

      要在 laravel 中扩展刀片,你必须告诉文件应该扩展你想要的部分。所以你要扩展的文件需要有一个@yield('sectionName') 才能正确扩展文件:所以你需要这个文件结构:

      base.blade.php

      @yield('title')
      <p>This is some sample text</p>
      

      part.blade.php

      @extends('base')
      @section('title')
      <h1>This is the title</h1>
      @endsection
      

      生成的文件如下所示

      <h1>This is the title</h1>
      <p>This is some sample text</p>
      

      【讨论】:

        【解决方案5】:

        你可能没有写

        @yield('content') in layout.dashboard 刀片模板

        或者你拼错了。尝试仔细检查@yield('content')@section('content') 中的拼写。希望它会有所帮助。

        【讨论】:

          猜你喜欢
          • 2014-04-14
          • 1970-01-01
          • 2020-04-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多