[英]pass variable from controller to template laravel
adminController.php
<?php
class AdminController extends BaseController {
protected $layout = 'layouts.admin';
/**
* Show the profile for the given user.
*/
public function register()
{
$this->layout->title = 'admin title';
$this->layout->menu_active = 'register';
$this->layout->content = View::make('pages.admin.register');
}
}
布局/ admin.blade.php
<!doctype html>
<html>
<head>
@include('includes.head')
</head>
<body>
<div class="container">
<header class="row">
@include('includes.header')
</header>
<div id="main" class="row">
@yield('content')
</div>
<footer class="row">
@include('includes.footer')
</footer>
</div>
</body>
</html>
包括/ head.blade.php
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="Scotch">
<title>@yield('title', 'default title')</title>
<!-- load bootstrap from a cdn -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/3.0.3/css/bootstrap-combined.min.css">
问题是
我如何在@yield上获得admin title
,而不是我在控制器上设置的default title
?
如何使用$ this-> layout-> variables传递模板中的变量?
如何在@yield上获得默认标题,而不是在控制器上设置的管理员标题?
在您的register
方法中,您使用以下行设置title
$this->layout->title = 'admin title';
您应该在view
使用{{ $title or 'Default Title' }}
。 在此处, or
用于在未定义给定变量时打印默认值。
如何使用$ this-> layout-> variable传递模板中的变量?
现在设置变量的方式,例如:
$this->layout->variable = 'value';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.