Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't pass data from controller to blade template laravel

In my page controller I have

$this->layout->content = View::make('authentication/login')->with('page_title','title');

I am using a blade file for my template. In the head of the html, I have

<title>{{$page_title}}</title>

I get an error that $page_title is undefined.

What I want ideally is a $data=array('page_title'=>'Login','second_item'=>'value').... But as I cannot get the basic passing of a variable to a view working, I am sticking with that first of all.

like image 927
Claire Avatar asked Feb 01 '26 00:02

Claire


2 Answers

There are many ways to achieve this, as @Gravy pointed out, but judging by the way she is trying to write the code, the solution would be:

$data = array();
$this->layout->with('data', $data);
$this->layout->content = View::make('home');

See more here: http://forums.laravel.io/viewtopic.php?pid=58548#p58548

like image 55
Glad To Help Avatar answered Feb 02 '26 13:02

Glad To Help


$data = 
[
    'page_title' => 'Login',
    'second_item' => 'value'
    ...
];

return View::make('authentication/login', $data);

// or

return View::make('authentication/login', compact('data'));

// or

return View::make('authentication/login')->with($data);

// or

return View::make('authentication/login')->with(['page_title' => 'Login', 'second_item' => 'value']);

// or

return View::make('authentication/login')->with(array('page_title' => 'Login', 'second_item' => 'value'));
like image 28
Gravy Avatar answered Feb 02 '26 13:02

Gravy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!