Laravel Blade-通过@include或@yield传递变量 [英] Laravel Blade - pass variable via an @include or @yield

查看:457
本文介绍了Laravel Blade-通过@include或@yield传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将变量传递给包含的Blade文件.我已经尝试过两种方法.但是,都没有成功.

I need to pass a variable to an included Blade file. I have attempted this two-ways; however, neither have been successful.

  1. 将变量title传递到包含的文件中:

  1. Pass a variable, title, to the included file:

@section('left')
    @include('modal', ['title' => 'Hello'])
@stop

  • 使用@yield并设置部分:

  • Use @yield and set the section:

    @section('left')
        @include('modal')
            @section('title')
            Hello
            @stop
    @stop
    

  • 我正在使用Laravel 4.2.我不知道自己想做的事是否可行,但我想是可以的.

    I am using Laravel 4.2. I am unaware if what I am trying to do is possible, but I imagine it is.

    推荐答案

    根据文档include方式应该是这样做的方式:

    According to the documentation, the include-way should be the way to do it:

    包括子视图

    @include('view.name')

    您还可以将数据数组传递到包含的视图:

    You may also pass an array of data to the included view:

    @include('view.name', array('some'=>'data'))

    我的直觉是$title与嵌套模板中的另一个变量冲突.仅用于故障排除,请尝试暂时调用其他名称.

    My hunch is that $title is conflicting with another variable in your nested templates. Just for troubleshooting, try temporarily calling it something else.

    这篇关于Laravel Blade-通过@include或@yield传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆