【问题标题】:Laravel @sectionLaravel @section
【发布时间】:2014-09-08 11:33:27
【问题描述】:

我的视图文件夹结构

  • 内容
    • home.blade.php
  • 包括
  • 部分
    • mainsection.blade.php
  • 布局
    • default.blade.php

我的 home.blade.php

@extends('layout.default')

@section('content')

@section('partials.mainsection')
        <div class="col-xs-10 col-xs-offset-1 col-md-8 col-md-offset-2 text-center">
               <h1>Some Text</h1>
        </div>
@stop

我的 mainsection.blade.php

<section class="section">
    <div class="container">
        <div class="row">
           @yield('section')
        </div>
    </div>
</section>

我的 default.blade.php

@include('layout.header')

<div id="wrapper">

    <header>
        <div class="container">
    @include('partials.mainNav')
        </div>
    </header>

    <div id="main">

    @yield('content')

    </div>


@include('layout.footer')

</div>

我的想法是我可以为我的内容使用 partials.mainsection 视图,这样我就不必每次都编写部分/容器/行代码。 所以我只在 @section('partials.mainsection') 中写了一些文本,它被 mainsection 视图包裹。

但这不起作用,我做错了什么还是有其他方法可以做到这一点?

“partials.mainsection”只是我的内容的包装,所以我不必每次都写这个。如果我只使用@include,我无法从每个视图中扩展它。

【问题讨论】:

    标签: php frameworks


    【解决方案1】:

    要将部分或任何其他部分包含到刀片模板中,语法为 @include('view.name')

    【讨论】:

    • 但是如果你只包含视图,你可以用你的文本来扩展它。
    • 查看此页面上的第一个示例:laravel.com/docs/templates 他们在部分视图中使用@parent,在他们想要使用的页面上使用@section@show
    猜你喜欢
    • 2017-01-18
    • 2018-04-25
    • 2017-05-01
    • 2017-11-18
    • 2016-05-19
    • 1970-01-01
    • 2019-01-12
    • 2017-05-16
    • 2021-09-27
    相关资源
    最近更新 更多