Laravel 产量和扩展不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39724003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:31:06  来源:igfitidea点击:

Laravel yield and extends not working

phplaravellaravel-5laravel-5.2blade

提问by Jaskaran Singh Puri

This is master.blade.php placed in views folder

这是放在views文件夹中的master.blade.php

<html ng-app="planner">
<head>
    <title>MeetUp Planner</title>

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/master.css" type="text/css">
</head>
<body ng-controller="MainController">
    <div class="container" ng-controller="MainController">
        <div class="row row-centered planner-block">
            <div class="col-md-12">
                <div class="col-md-5 col-centered col-min form-area">
                    <div class="row row-centered">
                        @yield('signup')
                    </div>
                </div>
            </div>
        </div>
    </div>
<script src="js/master.js"></script>
</body>
</html>

This is forms/signup.blade.php place in views folder

这是在视图文件夹中的 forms/signup.blade.php

@extends('master')

@section('signup')
    <div class="col-md-11 col-centered form-area-inner">
        <span class="form-text">Sign Up</span>
        <hr class="seperator"/>
    </div>
@stop

This is routes file

这是路由文件

<?php
Route::get('/', function () {
    return view('master');
});

The yield 'signup' is not wokring, the divs and text are not being show in the master file. What could be the problem?

产量“注册”无效,div 和文本未显示在主文件中。可能是什么问题呢?

Directory Structure

目录结构

resources:
---views->errors
---views->forms->signup.blade.php
---views->vendor
---views->master.blade.php

Using laravel 5.2

使用 Laravel 5.2

回答by Alexey Mezenin

That's not how it works. masterview will be extended when you'll use forms.signupview:

这不是它的工作原理。master当您使用forms.signup视图时,视图将被扩展:

Route::get('/', function () {
    return view('forms.signup');
});

If you want to include some view into masterview, you should use @include()clause.

如果你想在视图中包含一些master视图,你应该使用@include()子句。

回答by Mehul Kuriya

your route file will be

你的路由文件将是

<?php
Route::get('/', function () {
     return view('forms.signup');
});
?>

change the location of master.blade.php

更改 master.blade.php 的位置

move it to ---resources/views/layouts/master.blade.php

将其移动到 ---resources/views/layouts/master.blade.php

in your master.blade.php file change this line

在您的 master.blade.php 文件中更改这一行

@yield('signup')to @yield('content')

@yield('signup')@yield('content')

reference link : link

参考链接:链接