Laravel 4 Blade @include变量 [英] Laravel 4 Blade @include variable

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

问题描述

我试图用Laravel刀片做include,但是问题是它不能传递变量.这是我的示例代码:

I was trying to do include with Laravel blade, but the problem is it can't pass the variable. Here's my example code:

file_include.blade.php

file_include.blade.php

<?php
  $myvar = "some text";

main.blade.php

main.blade.php

@include('file_include')
{{$myvar}}

当我运行文件时,它返回错误未定义的变量:myvar".那么,如何将变量从包含文件传递到主文件?

When I run the file, it return the error "Undefined variable: myvar". So, how can I pass the variable from the include file to the main file?

谢谢.

推荐答案

为什么要将它从包含传递给调用模板?如果在调用模板中需要它,请在其中创建它,然后将其传递到包含的模板中,如下所示:

Why would you pass it from the include to the calling template? If you need it in the calling template, create it there, then pass it into the included template like this:

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

http://laravel.com/docs/templates 上的代码段

Above code snippet from http://laravel.com/docs/templates

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

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