2

だから、私は基本的にJavaScriptを事前にロードする必要があるコンポーネントを持っています。

マスター レイアウト:

//layouts/master.blade.php
...
@yield('scripts')
...
@include('forms.search')
...

私のコンポーネント:

//forms/search.blade.php
@section('scripts')
some scripts here
@stop
...

私が呼んでいるもの:

//main.blade.php
@extends('layouts.master')

これは動作しません。セクションはヘッダーに追加されません。私は何か間違ったことをしていますか、それともlaravelではまったく不可能ですか?

4

3 に答える 3

1

含める前にセクションを譲ろうとしています。だからこれを試してください。

//main.blade.php

@extends('layouts.master')

そして//layouts/master.blade.phpで

@include('forms.search')

そして//forms/search.blade.php

   some scripts here
于 2013-09-18T09:55:58.803 に答える
0

あなたが呼んでいる

@extends('layouts.master')

を持っている

@yield('scripts')

しかし、セクションスクリプトを宣言していますforms/search.blade.php

したがって、正しく調べると、間違ったブレード テンプレートでスクリプトを宣言している、または間違ったブレード テンプレートに yield 領域を配置しているlayouts/master.blade.php.何も拡張しないので、 @section を宣言しても問題ありません。

あなたが望むものを達成するために、

@section('scripts')
some scripts here
@stop 

セクションはmain.blade.phpファイルにある必要があります..

私がそれをするつもりなら、それは次のようになります:

レイアウト/master.blade.php

<html>
    <head>
        <!-- more stuff here -->

        @yield('scripts')
        <!-- or put it in the footer if you like -->
    </head>
    <body>
        @yield('search-form')
        @yield('content')
    </body>
</html>

フォーム/search.blade.php

//do whatever here

main.blade.php

@extends('layouts/master')

@section('scripts')
    {{ HTML::script('assets/js/search-form.js') }}
@stop

@section('search-form')
    @include('forms/search')
@stop

または、master.blade.phpmain.blade.php@yield('search-form')を完全に削除して、次のようにします。

@section('scripts')
    {{ HTML::script('assets/js/search-form.js') }}
@stop

@section('content')
    @include('forms/search')
    <!-- other stuff here -->
@stop
于 2013-09-18T13:08:09.333 に答える