【问题标题】:Php Laravel @yield or @section is not workingPhp Laravel @yield 或 @section 不起作用
【发布时间】:2017-07-13 00:20:24
【问题描述】:

我的产量或部分在这里不起作用是我的代码 我想我已经遵守了所有的规则。如您所见,我想调用 home.blade.php 我将其命名为 @section('content-page') 并使用 yield('content-page') 将其调用到 main.blade.php 但似乎产量或部分不起作用。以下是我的代码:

home.blade.php

@extends('layouts.masters.main')

@section('page-content')

@include('layouts.partials.nav')

<div id="myCarousel" class="carousel slide" data-ride="carousel">
              <!-- Indicators -->
            <ol class="carousel-indicators">
                <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                <li data-target="#myCarousel" data-slide-to="1"></li>
                <li data-target="#myCarousel" data-slide-to="2"></li>
                <li data-target="#myCarousel" data-slide-to="3"></li>
            </ol>

              <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                <div class="item active">
                    <img src="../custom/image/image-slider/1.jpg">
                </div>

                <div class="item">
                    <img src="../custom/image/image-slider/2.jpg">
                </div>

                <div class="item">
                    <img src="../custom/image/image-slider/3.jpg">
                </div>

                <div class="item">
                    <img src="../custom/image/image-slider/4.jpg">
                </div>
            </div>

              <!-- Left and right controls -->
            <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                <span class="sr-only">Previous</span>
            </a>
            <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                <span class="sr-only">Next</span>
            </a>
        </div>

        <div id="news-container">
            <h2>News</h2>
            <div class="strike">
                <span>Latest</span>
            </div>
            <div class="container">
                <div class="row">
                  <div class="col-sm-4">
                        <figure>
                            <img src="../custom/image/image-slider/3.jpg" height="300px;" width="100px;">

                            <figcaption>
                                <h3>I love this title!</h3>

                                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
                                eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>

                                <p><a href="../news/new.php">Read More</a></p>
                            </figcaption>
                        </figure>
                  </div>
                  <div class="col-sm-4">
                        <figure>
                            <img src="../custom/image/image-slider/2.jpg" height="300px;" width="100px;">

                            <figcaption>
                                <h3>I love this title!</h3>

                                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
                                eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>

                                <p><a href="../news/new.php">Read More</a></p>
                            </figcaption>
                        </figure>
                  </div>
                  <div class="col-sm-4">
                        <figure>
                            <img src="../custom/image/image-slider/1.jpg" height="300px;" width="100px;">

                            <figcaption>
                                <h3>I love this title!</h3>

                                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
                                eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>

                                <p><a href="../news/new.php">Read More</a></p>
                            </figcaption>
                        </figure>
                  </div>
                </div>
            </div>
        </div>  

        <div id="about-container">
            <h2>About</h2>
            <div class="strike">
                <span>Our Story</span>
            </div>
                <p>
                    There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc. There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form,

                </p>
        </div>  

        <div id="contact-container" style="background-color: whitesmoke;">
        <h2>Contact</h2>

        <div class="strike">
                <span>Our Contact</span>
        </div>
            <div class="container" style="padding: 35px;">
                <div class="row">
                    <div class="col-sm-6" style="background-color: whitesmoke; padding: 10px;">  
                        <form>
                          <div class="form-group">
                            <label for="name">Name:</label>
                            <input type="name" class="form-control" id="name" required id="name-textfield">
                          </div>
                          <div class="form-group">
                            <label for="email">Email:</label>
                            <input type="email" class="form-control" id="email" required id="email-textfield">
                          </div>
                          <div class="form-group">
                            <label for="message">Message:</label>
                            <textarea type="message" class="form-control" rows="4" cols="50" required id="message-textarea">
                            </textarea>
                          </div>
                          <button type="submit" class="btn btn-default">Send</button>
                        </form>         
                    </div>
                    <div class="col-sm-6" style="padding: 10px;">  
                          <div class="form-group">
                            <label >Address</label>
                            <p>O4F Vasile milea Blvd.Afi Park 2 Bucharest 6 Romania 061344</p>
                          </div>    
                          <div class="form-group">
                            <label >Phone</label>
                            <p> +46 (0)31 33 35 000</p>
                          </div>    
                          <div class="form-group">
                            <label >Email</label>
                            <p>info@sweetbasil-vail.com</p>
                          </div>    
                    </div>
                </div>  
            </div>  
        </div>  

@include('layouts.partials.footer')

@stop

路线代码

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', [
    'as' => 'home',
    'uses' => 'PagesController@home'
]);

页面控制器

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PagesController extends Controller
{
    public function home()
    {
        return view('layouts.masters.main'); 
    }
}

最后是我的 main.blade.php

<!DOCTYPE html>
<html>
    <head>
        <title>

            Forester | Home

        </title>

            <link rel="stylesheet" href="../custom/bootstrap/css/bootstrap.min.css">
            <!-- <script src="../HCI/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script> -->
            <!-- jQuery library -->
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

            <!-- Latest compiled JavaScript -->
            <script src="../custom/bootstrap/js/bootstrap.min.js"></script>

            <link rel="stylesheet" type="text/css" href="../custom/css/css.css">

    </head>

    <body>

        <div class="col-xs-12">

            @yield('page-content')

        </div>

    </body>

</html>

【问题讨论】:

  • 问题解决了吗?

标签: php laravel


【解决方案1】:

不确定这是否是问题所在,但您在 home.blade.php 文件末尾缺少 @endsection 标记

【讨论】:

    【解决方案2】:

    在您的控制器中,您必须将返回值更改为“layouts.masters.home”(而不是“layouts.masters.main”)。

    在您的视图目录中,您必须有一个名为“masters”的目录,其中必须有“main.blade.php”和“home.blade.php”

    【讨论】:

      猜你喜欢
      • 2017-11-18
      • 2021-03-29
      • 2017-11-18
      • 2019-01-12
      • 2021-09-27
      • 2017-05-16
      • 2015-07-06
      • 1970-01-01
      • 2015-05-18
      相关资源
      最近更新 更多