Php 如何从laravel 4中包含的视图修改布局剖面?
所以, 我基本上有一个组件,需要事先加载javascript 主布局:Php 如何从laravel 4中包含的视图修改布局剖面?,php,laravel,laravel-4,blade,Php,Laravel,Laravel 4,Blade,所以, 我基本上有一个组件,需要事先加载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')
//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根本不可能这样做?您试图在加入之前放弃该部分。所以试试这个 在//main.blade.php中
@extends('layouts.master')
@include('forms.search')
some scripts here
<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>
//do whatever here
@extends('layouts/master')
@section('scripts')
{{ HTML::script('assets/js/search-form.js') }}
@stop
@section('search-form')
@include('forms/search')
@stop
在//layouts/master.blade.php中
@extends('layouts.master')
@include('forms.search')
some scripts here
<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>
//do whatever here
@extends('layouts/master')
@section('scripts')
{{ HTML::script('assets/js/search-form.js') }}
@stop
@section('search-form')
@include('forms/search')
@stop
和//forms/search.blade.php
@extends('layouts.master')
@include('forms.search')
some scripts here
<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>
//do whatever here
@extends('layouts/master')
@section('scripts')
{{ HTML::script('assets/js/search-form.js') }}
@stop
@section('search-form')
@include('forms/search')
@stop
你在打电话吗
@extends('layouts.master')
哪个有一个
@yield('scripts')
但是您在forms/search.blade.php
因此,如果检查正确,则表明您在错误的刀片模板上声明脚本,或者您在错误的刀片模板上放置了屈服区域。。因为@yield在layouts/master.blade.php上,所以它已经在@include之前执行了,而@include并没有扩展任何内容,所以声明@section并不重要
为了达到你想要的,你需要
@section('scripts')
some scripts here
@stop
节应位于main.blade.php
文件中
如果我要这么做,应该是这样的:
layouts/master.blade.php
@extends('layouts.master')
@include('forms.search')
some scripts here
<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>
//do whatever here
@extends('layouts/master')
@section('scripts')
{{ HTML::script('assets/js/search-form.js') }}
@stop
@section('search-form')
@include('forms/search')
@stop
main.blade.php
@extends('layouts.master')
@include('forms.search')
some scripts here
<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>
//do whatever here
@extends('layouts/master')
@section('scripts')
{{ HTML::script('assets/js/search-form.js') }}
@stop
@section('search-form')
@include('forms/search')
@stop
或者在master.blade.php和main.blade.php上完全删除@yield('search-form')
,执行以下操作:
@section('scripts')
{{ HTML::script('assets/js/search-form.js') }}
@stop
@section('content')
@include('forms/search')
<!-- other stuff here -->
@stop
@节(“脚本”)
{{HTML::script('assets/js/search form.js')}
@停止
@节(“内容”)
@包括('表格/搜索')
@停止
我也遇到了同样的问题,让它对我起作用的是在我所有的部分中添加“@parent”
{{-- Main area where you want to "yield" --}}
@section('js')
@show
@section('js')
@parent
{{-- Code Here --}}
@stop
这当然是可能的,我已经做了好几次了。问题可能在于您的dir结构。你的
//layouts/master.blade.php
在哪里?它是否在views/layouts/master.blade.php
上?你的dir结构是什么样子的?结构有什么问题?所有内容都在代码注释中。所有文件都是由laravel加载的,它不是目录问题,问题是搜索表单和主模板不相关。主模板可以在没有此表单的情况下使用,并且表单可以位于我需要的任何其他位置。所以,据我所知,在主模板中没有办法做到这一点。不过,第一个版本可以在没有表单的情况下使用。如果需要,还可以在控制器级别包含模板。您只需使用一个容器(如)准备内容,然后准备一个包含搜索表单的子版面和一个不包含搜索表单的子版面。