我正忙于创建一个cms,在后台我有一个部分,您可以在其中选择页面的布局。现在布局的名称被保存到数据库中,我希望能够做这样的事情:如果联系人与布局相同。请显示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;
}
在我的家里。blade.php
{{ getTypeLayout() }}
您可以创建一个主模板。在此主页中,您可以插入内容
<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');
}