2014-10-09 40 views
1

我正在忙於創建cms並在後端中有一個部分,您可以在其中選擇頁面的佈局。目前,佈局的名稱被保存到數據庫中,我希望能夠做到這樣的事情: 如果contact與layouts.contact相同,則顯示contact.blade.php。 「contact」是從後端保存在數據庫中的佈局名稱,如果選擇「home」,則需要顯示home.blade.php。根據佈局調用視圖

我試圖創建一個幫助,但它不是顯示任何

function getTypeLayout($type = '') 
{ 

$layout = Page::where('type', '=', $type)->get(); 

switch($layout){ 
    case "home": 
     echo "home layout"; 
     break; 
    case "inside": 
     echo "inside layout"; 
} 

return $type; 
} 

,並在我的home.blade.php

{{ getTypeLayout() }} 

回答

2

您可以創建一個主模板。在這個母版頁可以插入內容

<html> 
    <body> 
     @section('sidebar') 
      This is the master sidebar. 
     @show 

     <div class="container"> 
      @yield('content') 
     </div> 
    </body> 
</html> 

這個網頁的內容看起來像

@extends('layouts.master') 

@section('sidebar') 


    <p>This is appended to the master sidebar.</p> 
@stop 

@section('content') 
    <p>This is my body content.</p> 
@stop 

在你的控制器,你可以決定你要通過DB值要使用的內容

protected $layout = 'layouts.master'; 

public function showLayout() 
{ 
    $this->layout->content = View::make('<DBvalue>.layout'); 
} 
+0

謝謝你太多了。這幫助了我很多 – user3656554 2014-10-09 08:57:13