Laravel blade 附加到部分无法正常工作

Laravel blade append to section not working properly

我想从视图写入我的模板中的一个区域,也想从包含的视图写入第一个视图,但无论我尝试什么,它都不起作用。我试过使用 @parent 和 @append 但到目前为止没有产生我想要的结果。

在我的布局中,我有以下内容:

@yield('scripts')

在我看来主要有以下几点:

@include('admin/rules/partials/_form')

@section('scripts)
    // javascript #1 here
@stop

在 admin/rules/partials/_form 我有以下内容:

@section('scripts)
    // javascript #2 here
@stop

所以就像我说的那样,我尝试在@section('scripts') 之后使用@parent,并且还使用@append 而不是@stop,但我没有做任何正确地包含这两个脚本块的事情。到目前为止我最好的是 javascript #1 被包含一次, javascript #2 被包含两次。我该怎么做才能使每个代码块仅附加到脚本区域一次?

对我有用。

编辑,但现在没有了。

EDIT,我更新了下面的代码以使其工作。我正在生成页面和布局上的 javascript 部分。

tests.layout.blade.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>
            @yield('title') - test
        </title>
        @yield('head')
    </head>
    <body>

    @yield('content')

    @yield('javascript')
    </body>
</html>

tests.page.blade.php

@extends('layouts.default')
@section('title', 'Poses')

@section('content')
    <div class="container">
        <div class="row">
            @include('tests.partials.one')
            @include('tests.partials.two')
        </div>
    </div>
@stop

tests.partials.one.blade.php

@section('content')
    @parent
    <h1>One</h1>
@stop

@section('javascript')
    @parent
    <script>Scripts from one</script>
@stop

tests.partials.two.blade.php

@section('content')
    @parent
    <h1>Two</h1>
@stop

@section('javascript')
    @parent
    <script>Scripts from two</script>
@stop

进一步参考:http://laravel.com/docs/5.0/templates

最后我解决了我不得不做以下事情:

@yield('scripts')

在我看来主要有以下几点:

@include('admin/rules/partials/_form')

@section('scripts)
    // javascript #1 here
@stop

在 admin/rules/partials/_form 我有以下内容:

@section('scripts)
    @parent
    // javascript #2 here
@overwrite

就我而言,我没有设置 @stop 部分。使用后@stop,正常使用