代码之家  ›  专栏  ›  技术社区  ›  Julian Mendez

叶片Laravel-产量和含量

  •  0
  • Julian Mendez  · 技术社区  · 6 年前

    经过一些无用的研究,我不得不问这个问题。 我用的是Laravel 5.6

    我有我的控制器

    public function index()
    {
        return view('layout.app');
    }
    

    其中app.blade.php如下所示:

    <html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
    @section('sidebar')
        This is the master sidebar.
    @show
    
    <div class="container">
        @yield('content')
    </div>
    </body>
    </html>
    

    child.blade.php是:

    @extends('app')
    
    @section('title', 'Page Title')
    
    @section('sidebar')
        @parent
    
        <p>This is appended to the master sidebar.</p>
    @endsection
    
    @section('content')
        <p>This is my body content.</p>
    @endsection
    

    这个文件看起来像Laravel教程,它们是,我尝试使用自己的文件,但仍然有相同的错误,所以为了简化使用Laravel的文件。

    所以我从来没见过child.blade.php 我在哪里卡住了有什么常见的错误吗?

    我以前做过这个,它做得很好,我建立的应用程序非常快,但现在我找不到解决方案。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Yudi Yohanes Septian Gotama    6 年前

    在控制器上需要调用子视图

    public function index()
    {
        return view('child');
    }
    

    因此控制器将调用子视图,子视图将调用应用视图,因为您在子视图的开头扩展了应用视图。