Sin*_*nan 4 php partial-views laravel
我正在使用laravel布局,我有这样的设置;
//控制器
public function action_index()
{
    $this->layout->nest('submodule', 'partials.stuff');
    $this->layout->nest('content', 'home.index');
}
//布局
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    @yield('content');
</body>
</html>
//这是内容模板
@section('content')
    <div>
        @yield('submodule')
    </div>
@endsection
我的问题是如何在"内容"部分中插入部分模板?我还需要将变量传递给第二个模板"子模块".
$this->layout->nest('partial', 'partials.partial');
这不起作用,因为它将视图绑定到布局.而我需要将它绑定到"内容"模板中定义的部分.
有任何想法吗?
小智 5
以下是我修复Laravel嵌套视图问题的方法:
使用此解决方案,您还可以将数据传递到主视图
解:
你需要在你的home/index.blade.php视图中渲染partials.stuff,然后在你的template.php中创建一个'home/index.blade.php'的'content'视图.
使用 <?php render('partials.stuff') ?>
首先让你的 home/index.blade.php:
<div>
      <?php render('partials.stuff') ?>
</div>
第二次渲染你的视图 - 没有任何嵌套的"子模块"调用
public function action_index()
{
    $this->layout->nest('content', View::make('home.index'),$data) ;
}
最后,您的模板将保持不变 - 渲染 {{ $content }}
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    {{ $content }}
</body>
</html>
希望这可以帮助你解决我的问题:)