亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel 中的布局頁面未獲得輸出

Laravel 中的布局頁面未獲得輸出

PHP
滄海一幻覺 2023-09-08 17:17:59
我是 Laravel 框架的新手,想要使用 Laravel 布局母版頁,并用于在母版頁中包含子頁面。這是我的頁眉和頁腳頁面,app.blade.php 是我的母版頁,我在其中使用 @yield 來顯示數據。但這對我不起作用。我的輸出顯示空白。app.blade.php(布局母版頁)    <!DOCTYPE html>    <html>    <head>        <meta charset="UTF-8">        <meta name="viewport" content="width=device-width, initial-scale=1.0">        <meta http-equiv="X-UA-Compatible" content="ie=edge">        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>                             <title>Master Page</title>    </head>    <body>            <div>                    <div>                            @yield('header')                    </div>                <div class="content">                    @section('content')                        <h1> Body </h1>                    @endsection            </div>                          <div>                                  @yield('footer')                          </div>                </div>        </body>    </html>
查看完整描述

3 回答

?
幕布斯6054654

TA貢獻1876條經驗 獲得超7個贊

問題: 您的刀片存在一些問題。

  1. 每個開始@section標簽都需要一個結束@endsection標簽。

  2. 標簽部分應該包含您想要在其間顯示的所有內容。

  3. 您不需要添加整個內容,<html> etc.只需添加必要的代碼即可

  4. 我認為內容應該是收益,因為您可能想在那里插入其他頁面的內容。

我還認為您很困惑@include,@yield 如果您想外包頁眉和頁腳,您可以簡單地 @include('yourFolder/footer') 并插入代碼


解決方案:

  1. 更改@yield@include

  2. 更改@section@yield('content')


例子:

文件名為:header.blade.php

  <div class="header">

     <center>  Layout Header Master page </center>

  </div>

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

    <title>Master Page</title>

</head>

<body>

        <div>

             @include('header')

        <div class="content">

             @yield('content')

        </div>

             @include('footer')

        </div>

   </body>

</html>

之后您可以創建一個新視圖:example.blade.php


@extends('layout.app')

@section('content')

//put your content here

@endsection


查看完整回答
反對 回復 2023-09-08
?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

header.blade.php(只需使用代碼刪除其他)


@section('header')

   <center>  Layout Header Master page </center>

@endsection

footer.blade.php(只需使用代碼刪除其他)


@section('footer')

   <center>   Layout Footer Master page </center>

@endsection

應用程序.blade.php


<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

    <title>Master Page</title>

</head>

<body>

        <div>

             <div class="header">

                 @include('header')

             </div>


        <div class="content">

             @yield('content')

        </div>

             <div class="footer">

                 @include('footer')

             </div>

        </div>

   </body>

</html>

學生控制器.php


   public function viewmasterpage()

   {

       return view('layouts.app');

   }


查看完整回答
反對 回復 2023-09-08
?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

您誤解了 @extends、@yield 和 @section 指令。


@extends 使用另一個刀片文件,并用它定義的 @sections 填充 @yield 指令。


說你有app.blade.php


<html>

    <body>

         @yield('header')


         @yield('content')


         @yield('footer')

    </body>

</html>

那么你可以說landing.blade.php


@extends('app')


@section('header')

    <header>I am the header for the landing page!</header>

@endsection


@section('content')

    <div>I am the content for the landing page!</div>

@endsection


@section('footer')

    <header>I am the footer for the landing page!</footer>

@endsection


查看完整回答
反對 回復 2023-09-08
  • 3 回答
  • 0 關注
  • 169 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號