Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 8.0叶片嵌套@extends@截面和@yield不工作_Php_Laravel_Frameworks - Fatal编程技术网

Php Laravel 8.0叶片嵌套@extends@截面和@yield不工作

Php Laravel 8.0叶片嵌套@extends@截面和@yield不工作,php,laravel,frameworks,Php,Laravel,Frameworks,我有这个template.blade.php,路径是views/templates/template.blade.php,代码如下: // template.blade.php // some codes here @include("templates.navigation.navigation") @yield('header') @yield('content') @include('templates.footer.footer') // some other

我有这个
template.blade.php
,路径是
views/templates/template.blade.php
,代码如下:

// template.blade.php


// some codes here

@include("templates.navigation.navigation")
@yield('header')
@yield('content')
@include('templates.footer.footer')

// some other codes here
现在,在我的路线中,
home.blade.php
(可在
视图/home/home.blade.php
中访问)被设置为登录页。主页需要借用一段代码(浮动按钮的代码。每个浮动按钮因当前页面而异)。以下是主页的代码:

// home.blade.php


@extends('templates.template')
@section('header')
    // some codes here
@endsection

@section('content')
    // some other codes here
    @yield('float-button-module-menu') // the code that needs to be accessed but doesn't work
@endsection
@yield('float-button-module-menu')
将在
视图/模板/float-buttons/float-buttons.blade.php中访问。以下是上述网页的代码:

// float-buttons.blade.php


@extends('home.home') // I suspect that I was wrong at declaring the name for the @extends here
@section('float-button-module-menu')
    // some codes inside the section that needs to be displayed
@endsection
为了简化问题,我需要从
float buttons.blade.php
内部
home.blade.php
访问
@部分('float-button-module-menu')
。我不知道这个逻辑范围内的问题

编辑以下是
float button.blade.php
中各部分的完整代码:

// float-button.blade.php


@extends('home.home')
@section('float-button-module-menu')
<div class="d-flex flex-column position-fixed button button-float-position-buttom-left">
    <div class="button-float d-flex">
        <span class="fas fa-user-cog text-lg text-white align-self-center mx-auto"></span>
    </div>
</div>
@endsection

@section('float-button-anchor')
<div class="button-float d-flex">
    <span class="fas fa-arrow-up text-lg text-white align-self-center mx-auto"></span>
</div>
@endsection

@section('float-button-help')
<div class="button-float d-flex">
    <span class="fas fa-question text-lg text-white align-self-center mx-auto"></span>
</div>
@endsection

// list of buttons would be updated.
//float-button.blade.php
@扩展('home.home')
@节(“浮动按钮-模块-菜单”)
@端部
@节(“浮动按钮锚定”)
@端部
@节(“浮动按钮帮助”)
@端部
//按钮列表将被更新。

扩展视图适用于直接调用/查看刀片文件时,例如通过
返回视图('templates.float buttons.float buttons')
。听起来这不是你想要的。您希望
@将该文件包含在
home.blade.php
中。进行以下更改:

home.blade.php:

@extends('templates.template')
@section('header')
    // some codes here
@endsection

@section('content')
    // some other codes here
    @include('templates.float-buttons.float-buttons')
@endsection
<div>
  My Float Buttons Code
</div>
@if ($type == 'anchor')
<div class="button-float d-flex">
    <span class="fas fa-arrow-up text-lg text-white align-self-center mx-auto"></span>
</div>

@elseif ($type == 'help')
<div class="button-float d-flex">
    <span class="fas fa-question text-lg text-white align-self-center mx-auto"></span>
</div>

@else
{{-- if no type parameter is given --}}
<p>
  Parameter 'type' is required
</p>
@endif
float-buttons.blade.php:

@extends('templates.template')
@section('header')
    // some codes here
@endsection

@section('content')
    // some other codes here
    @include('templates.float-buttons.float-buttons')
@endsection
<div>
  My Float Buttons Code
</div>
@if ($type == 'anchor')
<div class="button-float d-flex">
    <span class="fas fa-arrow-up text-lg text-white align-self-center mx-auto"></span>
</div>

@elseif ($type == 'help')
<div class="button-float d-flex">
    <span class="fas fa-question text-lg text-white align-self-center mx-auto"></span>
</div>

@else
{{-- if no type parameter is given --}}
<p>
  Parameter 'type' is required
</p>
@endif
float-buttons.blade.php:

@extends('templates.template')
@section('header')
    // some codes here
@endsection

@section('content')
    // some other codes here
    @include('templates.float-buttons.float-buttons')
@endsection
<div>
  My Float Buttons Code
</div>
@if ($type == 'anchor')
<div class="button-float d-flex">
    <span class="fas fa-arrow-up text-lg text-white align-self-center mx-auto"></span>
</div>

@elseif ($type == 'help')
<div class="button-float d-flex">
    <span class="fas fa-question text-lg text-white align-self-center mx-auto"></span>
</div>

@else
{{-- if no type parameter is given --}}
<p>
  Parameter 'type' is required
</p>
@endif
@if($type=='anchor')
@elseif($type=='help')
@否则
{{--如果没有给出类型参数--}

参数“type”是必需的

@恩迪夫
然后,您基本上可以在需要时使用
@include('templates.float buttons.float buttons'、['type'=>'anchor'])
@include('templates.float buttons.float buttons'、['type'=>'help'])
。当然,您可以随意扩展列表



注意:imho更优雅的解决方案是为您的每个案例创建单个刀片文件(“float-buttons-anchor.blade.php
float-buttons-help.blade.php
…),然后包含您需要的文件:
@include('templates.float-buttons.float-buttons-help'))

扩展视图适用于直接调用/查看刀片文件时,例如通过
返回视图('templates.float buttons.float buttons')
。听起来这不是你想要的。您希望
@将该文件包含在
home.blade.php
中。进行以下更改:

home.blade.php:

@extends('templates.template')
@section('header')
    // some codes here
@endsection

@section('content')
    // some other codes here
    @include('templates.float-buttons.float-buttons')
@endsection
<div>
  My Float Buttons Code
</div>
@if ($type == 'anchor')
<div class="button-float d-flex">
    <span class="fas fa-arrow-up text-lg text-white align-self-center mx-auto"></span>
</div>

@elseif ($type == 'help')
<div class="button-float d-flex">
    <span class="fas fa-question text-lg text-white align-self-center mx-auto"></span>
</div>

@else
{{-- if no type parameter is given --}}
<p>
  Parameter 'type' is required
</p>
@endif
float-buttons.blade.php:

@extends('templates.template')
@section('header')
    // some codes here
@endsection

@section('content')
    // some other codes here
    @include('templates.float-buttons.float-buttons')
@endsection
<div>
  My Float Buttons Code
</div>
@if ($type == 'anchor')
<div class="button-float d-flex">
    <span class="fas fa-arrow-up text-lg text-white align-self-center mx-auto"></span>
</div>

@elseif ($type == 'help')
<div class="button-float d-flex">
    <span class="fas fa-question text-lg text-white align-self-center mx-auto"></span>
</div>

@else
{{-- if no type parameter is given --}}
<p>
  Parameter 'type' is required
</p>
@endif
float-buttons.blade.php:

@extends('templates.template')
@section('header')
    // some codes here
@endsection

@section('content')
    // some other codes here
    @include('templates.float-buttons.float-buttons')
@endsection
<div>
  My Float Buttons Code
</div>
@if ($type == 'anchor')
<div class="button-float d-flex">
    <span class="fas fa-arrow-up text-lg text-white align-self-center mx-auto"></span>
</div>

@elseif ($type == 'help')
<div class="button-float d-flex">
    <span class="fas fa-question text-lg text-white align-self-center mx-auto"></span>
</div>

@else
{{-- if no type parameter is given --}}
<p>
  Parameter 'type' is required
</p>
@endif
@if($type=='anchor')
@elseif($type=='help')
@否则
{{--如果没有给出类型参数--}

参数“type”是必需的

@恩迪夫
然后,您基本上可以在需要时使用
@include('templates.float buttons.float buttons'、['type'=>'anchor'])
@include('templates.float buttons.float buttons'、['type'=>'help'])
。当然,您可以随意扩展列表



注意:imho更优雅的解决方案是为您的每个案例创建单个刀片文件(“float-buttons-anchor.blade.php
float-buttons-help.blade.php
…),然后包含您需要的文件:
@include('templates.float-buttons.float-buttons-help'))

您是否在某处调用/查看
float buttons.blade.php
自身?听起来你想把('float-buttons')
包含在你的
home.blade.php
@bromber中,我试过
include('template.float-buttons.float-buttons')
,但没有
@section()
@extends()
包含('float-buttons')
。我在
@include
中声明名称的方式是否有问题?不,听起来不错。确保您的
浮动按钮.blade.php
仅包含要显示的代码,从ITI中删除
@extends
@section
,如果我将在
浮动按钮.blade.php
中删除
@extends
@section
,则,那么我应该如何在
home.blade.php
内部调用
float buttons.blade.php
?您是否在某处调用/查看
float buttons.blade.php
本身?听起来你想把('float-buttons')
包含在你的
home.blade.php
@bromber中,我试过
include('template.float-buttons.float-buttons')
,但没有
@section()
@extends()
包含('float-buttons')。我在
@include
中声明名称的方式是否有问题?不,听起来不错。确保您的
浮动按钮.blade.php
仅包含要显示的代码,从ITI中删除
@extends
@section
,如果我将在
浮动按钮.blade.php
中删除
@extends
@section
,则,那么我应该如何调用
float button.blade.php
inside
home.blade.php
?这个逻辑是可以的,但是我需要访问
float button代码作为部分,这样我就可以只重用将在系统中重复的部分。我尝试过这个解决方案,但它会膨胀我的系统编辑它不会膨胀系统,但我需要根据页面动态访问部分。抱歉,我不明白这一点。您是否有多个浮动按钮代码,并希望选择显示哪一个?!还是有点困惑,对不起;)如果我理解你是正确的,浮动按钮中有多个部分,你需要根据你所在的页面显示不同的部分吗?就我个人而言,我会为每个人创建一个模板