【问题标题】:Laravel blade sections inside an included view (bladeception)包含视图内的 Laravel 刀片部分(刀片接收)
【发布时间】:2016-12-29 00:50:37
【问题描述】:

我的刀片结构有问题。我有一个基本布局模板、一个内容页面模板和子模板。

以下sn-ps作为参考

基础模板

<!DOCTYPE html>
<html lang="en">
    @include('head')
</head>

<body>
@include('body-open')
@yield('main')
@include('footer')
@include('body-close')

</body>
</html>

内容模板

@extends('base')
@section('main')
    content

@include('my-other-section-that-has-another-section-declaration-inside')

@overwrite

@section('body.script')
this is an extended script
@stop

body-close 模板

@section('body-open')
    this is the original content
@stop

my-other-section-that-has-another-section-declaration-inside 模板

this is cool

@section('body-open')
    @parent
    this should append to body open.
@stop

这是我的预期结果

<!DOCTYPE html>
<html lang="en">

</head>

<body>
this is the original content
this should append to body open.

content

this is cool
</body>
</html>

但我得到的是这个内容

<!DOCTYPE html>
<html lang="en">

</head>

<body>
this is the original content

content
this is cool

</body>
</html>

请注意,this 应该附加到 body open。 行已被跳过并且不会附加到其预期的部分。

我的代码有问题吗?或者这种方法可行吗?

谢谢!

【问题讨论】:

    标签: templates laravel-4 blade


    【解决方案1】:

    检查您的包含订单。

    你正在加载这个部分:my-other-section-that-has-another-section-declaration-inside template first:

    @section('body-open')
        @parent
        this should append to body open.
    @stop
    

    在上面你试图打电话给@parent - 但是这个是空的,所以你现在在body-open部分只有这个:this should append to body open.

    在此之后:@include('body-close') 你会得到:

    @section('body-open')
        this is the original content
    @stop
    

    ...没有 @parent 调用 - 因此您将使用:this is the original content 覆盖此部分 - 这就是您在这里所能期待的。您可以尝试像这样修复它:

    @section('body-open')
        this is the original content
        @parent
    @stop
    

    【讨论】:

    • 好的,我们会尽快回复您。感谢@filip-koblański 的回答
    猜你喜欢
    • 2015-08-20
    • 2013-11-22
    • 1970-01-01
    • 2014-09-15
    • 2018-05-02
    • 2014-11-13
    • 2013-07-29
    • 2013-08-03
    • 2014-06-28
    相关资源
    最近更新 更多