简体   繁体   English

php Laravel @yield或@section无法正常工作

[英]Php Laravel @yield or @section is not working

My yield or section is not working here is my code i think i already follow all the rules. 我的产量或部分无法正常工作,这是我的代码,我想我已经遵守了所有规则。 As you can see I want to call the home.blade.php i name it as a @section('content-page') and call it to the main.blade.php using yield('content-page') but it seems the yield or section is not working. 如您所见,我想调用home.blade.php,我将其命名为@section('content-page'),然后使用yield('content-page')将其命名为main.blade.php。产量或部分不起作用。 here are my codes below: 这是我的代码如下:

home.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

the route code 路线代码

/*
|--------------------------------------------------------------------------
| 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'
]);

The PageController PageController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

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

And Lastly my main.blade.php 最后是我的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>

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

In your controller, you must change return value to "layouts.masters.home" (instead of "layouts.masters.main"). 在控制器中,必须将返回值更改为“ layouts.masters.home”(而不是“ layouts.masters.main”)。

And in your view directory you must have a directory called "masters" and inside it you must have "main.blade.php" and "home.blade.php" 并且在您的视图目录中,您必须具有一个名为“ masters”的目录,并且在其中必须具有“ main.blade.php”和“ home.blade.php”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM