【发布时间】:2021-03-29 03:31:28
【问题描述】:
我有这个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(可通过views/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') 将通过views/templates/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 访问@section('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-buttons.blade.php本身?听起来你想在你的home.blade.php里面@include('float-buttons') -
@brombeer 我试过
include('template.float-buttons.float-buttons')没有@section()和@extends()在float-buttons.blade.php中,但不是@include('float-buttons')。我在@include中声明名称的方式有什么问题吗? -
不,听起来不错。确保您的
float-buttons.blade.php仅包含您要显示的代码,从中删除@extends和@section -
如果我将
@extends和@section放在float-buttons.blade.php中,那么我应该如何在home.blade.php中调用float-buttons.blade.php?
标签: php laravel frameworks