Laravel multiple nested views

▼魔方 西西 提交于 2019-12-04 10:56:25
deepika jain

Here is how I fixed the Laravel nested Views problem:

Using this solution you pass data to your main View as well

Solution:

You need to render the partials.stuff inside your home/index.blade.php view and then make a view to render 'content' of 'home/index.blade.php' in your template.php

Use <?php render('partials.stuff') ?>

First make your home/index.blade.php:

<div>
      <?php render('partials.stuff') ?>
</div>

Second render your view -- without any nested 'submodule' call

public function action_index()
{
    $this->layout->nest('content', View::make('home.index'),$data) ;
}

Finally Your template will remain same -- render {{ $content }}

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    {{ $content }}
</body>
</html>

Hope this helps you as it has solved my problem :)

Here's what you would typically do:

public function action_index()
{
    $this->layout->nest('content', View::make('home.index')->nest('submodule', 'partials.stuff'));
}

And in your template:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    {{ $content }}
</body>
</html>

and your home/index.blade.php:

<div>
     {{ $submodule }}
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!