php - pass variable from controller to template laravel -
admincontroller.php
<?php class admincontroller extends basecontroller { protected $layout = 'layouts.admin'; /** * show profile given user. */ public function register() { $this->layout->title = 'admin title'; $this->layout->menu_active = 'register'; $this->layout->content = view::make('pages.admin.register'); } }
layout/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>
includes/head.blade.php
<meta charset="utf-8"> <meta name="description" content=""> <meta name="author" content="scotch"> <title>@yield('title', 'default title')</title> <!-- load bootstrap cdn --> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/3.0.3/css/bootstrap-combined.min.css">
question
how
admin title
on @yield ratherdefault title
set on controller?how can use $this->layout->variable pass variables in templates?
how default title on @yield rather admin title set on controller?
in register
method setting title
using following line
$this->layout->title = 'admin title';
you should use {{ $title or 'default title' }}
in view
. here, or
used print default value when given variable undefined.
how can use $this->layout->variable pass variables in templates?
the way setting variables right now, example:
$this->layout->variable = 'value';
Comments
Post a Comment