加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – Laravel多个嵌套视图

发布时间:2020-12-14 19:43:22 所属栏目:大数据 来源:网络整理
导读:我正在使用laravel布局,我有这样的设置; //控制器 public function action_index(){ $this-layout-nest('submodule','partials.stuff'); $this-layout-nest('content','home.index');} //布局 !doctype htmlhtml lang="en"head meta charset="UTF-8" titleDo
我正在使用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');

这不起作用,因为它将视图绑定到布局.而我需要将它绑定到“内容”模板中定义的部分.

有任何想法吗?

解决方法

以下是我修复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>

希望这可以帮助你解决我的问题:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读