【问题标题】:Laravel 4 with blade and subsectionsLaravel 4 带刀片和分段
【发布时间】:2014-01-25 08:39:48
【问题描述】:

可以在 Laravel 4 的刀片模板内创建小节,例如:

布局/default.blade.php

<html>
 <head>
   @section('header')
   @show
 </head>
 <body>
   @yield('content')
 </body>
</html>

布局/sidemenu.blade.php

@section('sidemenu')
 <div>
  ....
  @section('subsidemenu')
  <!-- user permission depend menu -->
  @show
 </div>
@show

布局/header.blade.php

some header parameters

布局/content.blade.php

@extends('layouts/default')
   @section('header')
   @parent
   @show
   @include('layouts/sidemenu.blade.php')
   @section('subsidemenu')
   @parent
   @show
@stop

【问题讨论】:

    标签: templates laravel-4 blade


    【解决方案1】:

    如果您愿意,您的layouts/content.blade.php 看起来有点凌乱或不完整。首先,您没有定义“内容”部分本身。另外,如果您不打算修改它,我建议使用“@stop”关闭子视图中的部分,并且不要从父视图中定义部分。为layouts/content.blade.php尝试这样的事情:

    @extends('layouts/default')
    
    @section('content')
    ...
    @include('layouts/sidemenu.blade.php')
    ...
    @stop
    

    并且 subsidemenu 块可以包含在 sidemenu 中:

    @section('sidemenu')
    <div>
    ....
    @section('subsidemenu')
    <!-- user permission depend menu -->
    @stop
    </div>
    @stop
    

    【讨论】:

    • 好的,谢谢回复。我还有一个问题。我可以覆盖或调用 content.blade.php 中的 subside 部分吗?所以我想为管理员、版主、公众创建更多的内容文件...... ' 侧边菜单,在每个内容文件(管理员、版主、用户...)中,我想添加用户依赖菜单项。有可能还是您有更好的主意?
    • 可能你云试nest()方法。 $view = View::make('root.view')-&gt;nest('sidemenu', 'admins.sidemenu', $data); 并根据用户角色选择侧边菜单视图('admins.sidemenu')。
    猜你喜欢
    • 2013-11-12
    • 2013-08-03
    • 2013-11-22
    • 2014-09-15
    • 2014-03-06
    • 2014-07-28
    • 1970-01-01
    • 2013-05-08
    • 2019-05-16
    相关资源
    最近更新 更多