duanmao1919 2014-09-29 01:21
浏览 120
已采纳

Blade @include如何使用变量?

I just started working with Laravel / Blade a few weeks ago and was wondering how Blade @include works.

I have a top level index view that then includes some other views. These other views require specific variables, which I know you can pass in through @include.

I also have a controller which creates the top level view. The controller is where I pass in the variables. And it seems that once they've been passed in to the top view, I don't need to pass them in to the sub views.

For a visual

controller
    View::make('index', array('abc' => $abc))
index.blade.php
    @include('sub.piece') - Do I still need to pass in the array with abc here?
sub/piece.blade.php
    {{ abc }}

Does @include work like other includes where it's essentially a copy paste?

  • 写回答

1条回答 默认 最新

  • dougu3290 2014-09-29 01:59
    关注

    You do not have to pass in data that is already available to the parent view.

    Passing data in @include is useful for when the variable name differs for the two views.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败