有没有办法在父视图中声明的子视图中生成一个部分?
如果我在主视图中产生('custom_code')它的工作。
我做错了什么?
主视图
<html>
@include('client.acccount')
<h1>In Master</h1>
@yield('bookInfo')
</html>
子视图
@extends('layouts.Master')
/*
I also tried that
@section('custom_code')
@parent
@endsection
*/
@section('bookInfo')
<h1>In Child View</h1>
@yield('custom_code')
@endsection
client.acccount文件
@include('load_db_code')
load_db_code文件
<?php
$agent = Agent::find(Auth::id());
$lang = Cache::get("lang");
$temp = "";
if (Session::has('demo'))
{
$temp = "temp_";
}
?>
@if($lang == 'fr')
@if($agent->apparenceb2c->{$temp.'header_fr'} != "")
@section('custom_code')
{{ $agent->apparenceb2c->{$temp.'header_fr'} }}
@endsection
@endif
@endif
答案 0 :(得分:0)
由于继承的方向,您无法在子视图中使用@yield
。
不是将custom_code
放在一个部分中,而是将其放在基于文件的视图中(例如,custom_code.blade.php
)并使用:
@include('custom_code')
而不是
@yield('custom_code')
答案 1 :(得分:0)
你可以这样做:
2013-01-04T15:51:45+05:30
// parent.blade.php
@yield('footer', view('layouts.footer'))
// The footer is shown by default
// child.blade.php
@section('footer', '')