刀片中的嵌套部分 [英] Nesting sections in Blade

查看:65
本文介绍了刀片中的嵌套部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看Blade如何实现@section,但是它的工作方式与我使用Twig时有所不同.看来您无法将@sections相互嵌套.

I'm looking at how Blade implements the @section, but it works a little different than I'm used to with Twig. It seems that you can't nest @sections in each other.

示例:

_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 (常见问题页面的实现)

faq.blade.php (implementation for the faq-page)

@extend('website.blade.php')

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

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

而且我无法使用@includes解决它,因为我希望能够灵活地确定子视图中的子子节并覆盖其内容.

And I can't solve it with @includes, since I want the flexibility to be able to determine sub-sub sections in sub-views and overwrite their content.

推荐答案

没关系,这种是可能的是我的编辑器(PhpStorm)困扰着我.您可以 CAN 彼此嵌套@section,然后在扩展模板中覆盖/重新定义它们^^

Never mind, this is possible It was my editor (PhpStorm) that was bugging me. You CAN nest @section in each other and overwrite/redefine them in extended templates ^^

W00000t

这篇关于刀片中的嵌套部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆