laravel - Blade 中的嵌套部分

标签 laravel laravel-blade

我正在研究 Blade 如何实现 @section,但它的工作方式与我习惯的 Twig 略有不同。看来你不能将 @sections 嵌套在一起。

示例:

_layout.blade.php(基本布局文件)

<html>

    //favicons
    //meta content
    //other basic shizzle

    <head>
        <title>overal</title>
    </head>

    <body>
        @yield('body_content')
    </body>

</html>

website.blade.php(具体实现)

@extend('_layout.blade.php')

@section('body_content')

    <div class="">
        website-header
    </div>

    <div class="main">

        @section('navigation')
            <nav>website navigation</nav>
        @endsection

        <div class="website">

            {-- the actual content --}
            @yield('content')

        </div>

    </div>

@endsection

blog.blade.php(博客页面的实现)

@extend('website.blade.php')

@section('content')
    blog-items
@endsection

faq.blade.php(常见问题页面的实现)

@extend('website.blade.php')

{{-- we don't want the navigation here or want something different --}}
@section('nav')@endsection

@section('content')
    faq-items
@endsection

我无法使用 @includes 解决这个问题,因为我希望能够灵活地确定 subview 中的子子部分并覆盖其内容。

最佳答案

没关系,这可能的 困扰我的是我的编辑(PhpStorm)。您可以将@section嵌套在一起,并在扩展模板中覆盖/重新定义它们^^

W00000t

关于laravel - Blade 中的嵌套部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48425076/

相关文章:

php - 在 laravel 5.2 中显式插入 `id` 自动增量主键字段

mysql - 用户登录时如何更新 updated_at 列?

php - 如何验证在 Laravel 中更新电子邮件的用户的唯一电子邮件?

php - laravel-> 选择更改,提交给 Controller show

laravel-blade - 没有 & 的 Laravel getQueryString()

php - laravel 不使用已发布的 View

php - Laravel 粗鲁显示为空

php - mysql "or"查询操作的顺序

laravel-5.3 - .blade.php 模板中的注释

php - Laravel 中的 Cron 作业