Support the ongoing development of Laravel.io →
Views Blade Architecture
Last updated 2 years ago.
0

I hardly know what you are trying to say...

With the code example you used, you should have the $title and $games variables available in your view.

// games/list.blade.php
<h1>{{ $title }}</h1>

But if you don't use @extends than you have to create the entire html structure for every blade file you have. Take a look at the documentation:

Blade

View

Last updated 2 years ago.
0

I'll try to be a bit clearer.

I have a file in /views/layout.blade.php. It contains whole HTML template with <head>, <body> etc. Now I want to use it on every page, but without having to declare @extends('layout') in each one of them, because that's repetitive and messy. I use one layout everywhere, so I want to automate this.

Let's say my /views/layout.blade.php is (simplified example):

<html>
	<head>
		<title>{{ $title }}</title>
	</head>
	<body>
		{{ $content }}
	</body>
</html>

Now my /views/games/list.blade.php is:

<ul>
	@foreach ($games as $game)
		<li>{{ $game.title }}</li>
	@endforeach
</ul>

And GameController has a method:

public function show() {
	$games = Game::all();

	return View::make('games.list', array(
		'title' => 'All games',
		'games' => $games
	));
}

As you can see, I return the subview, which is supposed do be nested in the layout by $content variable. I know how to pass it explicitely, but what I need to do is to automate the process. So each returned view should be nested in my layout as $content. Plus, $title variable from returned view should be passed to the layout, and others not.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kokokurak kokokurak Joined 21 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.