所以, 我基本上有一个组件,需要事先加载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?
答案 0 :(得分:1)
您试图在包含之前产生该部分。试试吧。
在 // main.blade.php
中@extends('layouts.master')
在 // layouts / master.blade.php
中@include('forms.search')
// forms / search.blade.php
some scripts here
答案 1 :(得分:0)
@extends('layouts.master')
有一个
@yield('scripts')
但您要在forms/search.blade.php
因此,如果您正确检查,则在错误的刀片模板上声明脚本,或者您已将屈服区域放在错误的刀片模板上..因为@yield位于layouts/master.blade.php
上,所以它已被执行已经在@include之前,它没有任何扩展,所以声明@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.php 上完全删除@yield('search-form')
,在 main.blade.php 上删除{/ p>
@section('scripts')
{{ HTML::script('assets/js/search-form.js') }}
@stop
@section('content')
@include('forms/search')
<!-- other stuff here -->
@stop
答案 2 :(得分:0)
我遇到了同样的问题,为我工作的是在我的所有部分添加“@parent”......
{{-- Main area where you want to "yield" --}}
@section('js')
@show
@section('js')
@parent
{{-- Code Here --}}
@stop