2016-08-22 45 views
1

我的刀片結構有問題。我有一個基本佈局模板,一個內容頁面模板和子模板。Laravel刀片部分內包含視圖(bladeception)

採取以下片段作爲您的參考

基本模板

<!DOCTYPE html> 
<html lang="en"> 
    @include('head') 
</head> 

<body> 
@include('body-open') 
@yield('main') 
@include('footer') 
@include('body-close') 

</body> 
</html> 

內容模板

@extends('base') 
@section('main') 
    content 

@include('my-other-section-that-has-another-section-declaration-inside') 

@overwrite 

@section('body.script') 
this is an extended script 
@stop 

身體接近模板

@section('body-open') 
    this is the original content 
@stop 

我,其他截面,也就是說,有-另一截面聲明,內模板

this is cool 

@section('body-open') 
    @parent 
    this should append to body open. 
@stop 

這是我預期的結果

<!DOCTYPE html> 
<html lang="en"> 

</head> 

<body> 
this is the original content 
this should append to body open. 

content 

this is cool 
</body> 
</html> 

但是我得到這個內容而不是

<!DOCTYPE html> 
<html lang="en"> 

</head> 

<body> 
this is the original content 

content 
this is cool 

</body> 
</html> 

請注意,行這應該附加到身體打開。已被跳過,不會附加到其預期的部分。

我的代碼有問題嗎?或者這種方法可行嗎?

謝謝!

回答

0

檢查您的包括訂單。在上面你想打電話@parent

@section('body-open') 
    @parent 
    this should append to body open. 
@stop 

- 但是這一個是空的,所以你只有這在體開

你加載此部分:my-other-section-that-has-another-section-declaration-inside template第一部分:this should append to body open.現在。

在此之後:@include('body-close')你將得到:

@section('body-open') 
    this is the original content 
@stop 

...沒有@parent呼喊 - 所以你會覆蓋本節:this is the original content - 並且那你可以期待在這裏。您可以嘗試修復它是這樣的:

@section('body-open') 
    this is the original content 
    @parent 
@stop 
+0

好的,會在這個問題上回復您。謝謝@ filip-koblański爲您的答案 – stephenricks1991

+0

這是否有幫助嗎? –

+0

是的。感謝filip! – stephenricks1991