首页 > 解决方案 > 如何在 Laravel 刀片引擎的另一个视图中插入视图

问题描述

如何在 laravel 刀片引擎的另一个视图中插入视图刀片

我正在一个包含以下项目的项目中工作:主页视图......“ home.blade.php

我想添加另一个页面“ home2.blade.php

所以最后我得到了 1 页,它是“ home.blade.php ”,但它包含“ home2.blade.php

这是 home2.blade.php

@extends('layouts.app')

@section('content')

<!-- All Posts -->
@if(count($posts) > 0)

<div class="panel panel-default">
    <div class="panel-heading">
        All Posts
    </div>

    <div class="panel-body">
        <table class="table table-striped task-table">

            <!-- Table Headings -->
            <thead>
                <th>Title</th>
                <th>Content</th>
            </thead>

            <!-- Table Body -->
            <tbody>
            @foreach($posts as $post)
                <tr>
                    <td class="table-text">
                        <div>{{$post->title}}</div>
                    </td>
                    <td class="table-text">
                        <div>{{$post->content}}</div>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>

  @endif

  @endsection

这是“ home.blade.php

<html lang="en">
<head>
<meta charset="utf-8">

</head>

 <body data-spy="scroll" data-offset="0" data-target="#navigation">


  <!-- Fixed navbar -->
  <div id="navigation" class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" 
  data-target=".navbar-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>

    </div>

标签: phplaravelviewlaravel-blade

解决方案


include()在 home.blade.php 中使用

例如:如果您的 home2 位于resources/views/

@include('home2')

推荐阅读