2016-03-24 26 views
1

是否有一種方法可以在父視圖中聲明的子視圖中生成子節視圖?Laravel在父子視圖中生成父子節

如果我在主視圖中產生('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

由於繼承傳播的方向,您不能在子視圖中使用@yield

而不是把custom_code在一節的,把它放在一個基於文件視圖(例如,custom_code.blade.php)及用途:中

@include('custom_code') 

代替

@yield('custom_code') 
+0

我得到這個錯誤:查看[custom_code]未找到。 custom_code不是視圖 – user2942945

+0

custom_code的內容是什麼? –

+0

從正確的客戶端加載的html/css db – user2942945