Cannot find layout with laravel5 - php

I am getting this error:
View [layouts.master] not found. (View: C:\xampp5\htdocs\laravel\laravel\resources\views\page.blade.php)
This is my master.blade.php:
<html>
<head>
<title>#yield('title')</title>
</head>
<body>
#section('sidebar')
This is the master sidebar.
#show
<div class = "container">
#yield('content')
</div>
</body>
</html>
This is the page.blade.php:
#extends('layouts.master')
#section('title', 'Page Title')
#section('sidebar')
#parent
<p>This is appended to the master sidebar.</p>
#endsection
#section('content')
<h2>{{$name}}</h2>
<p>This is my body content.</p>
#endsection
And here is the relevant section of route:
Route::get('blade', function () {
return view('page',array('name' => 'Random Name'));
});

Put master.blade.php in this directory:
C:\xampp5\htdocs\laravel\laravel\resources\views\layouts
Or change path for the layout:
#extends('layouts.master')
to this:
#extends('master')

Do like this
#extends('master')
#section('title', 'Page Title')
#section('sidebar')
#parent
<p>This is appended to the master sidebar.</p>
#endsection
#section('content')
<h2>{{$name}}</h2>
<p>This is my body content.</p>
#endsection

Related

My Blade template content displayed twice

I'm newbie in laravel. When I try to make master layout example, I get the content of my view printed out twice.
master.blade.php:
<html>
<head>
<title>#yield('title')</title>
</head>
<body>
#section('sidebar')
This is the master sidebar.
#show
<div class="container">
#yield('content')
</div>
</body>
</html>
page.blade.php:
#extends('layouts.master')
#section('title', 'Page Title')
#section('sidebar')
<p>This is appended to the master sidebar.</p>
#endsection
#section('content')
<p>This is my body content.</p>
#endsection
and my Route web.php:
Route::get('blade', function () {
return view('page');
});
I trying use #stop intead of #endsection but it doesn't work.

parent & show element in Laravel freamwork?

i'm learning Laravel frame work, and have a question:
in this code:
<!DOCTYPE HTML>
<html>
<body>
<nav>
#section('nav')
<a>Home page</a>
#show
</nav>
<div id="content">
#yield('content')
</div>
</body>
</html>
what to do: #show ?!
Having a layout (layout.blade.php) view of
<!DOCTYPE HTML>
<html>
<body>
<nav>
#section('nav')
<a>Home page</a>
#show
</nav>
<div id="content">
#yield('content')
</div>
</body>
</html>
And a view (users.blade.php) of
#extends('layout')
#section('nav')
> <a>Users</a>
#stop
You should see rendered:
Home page > Users
But you could also use stop on layout:
#section('nav')
<a>Home page</a>
#stop
And #parent on your view:
#section('nav')
#parent
> <a>Users</a>
#stop
Take a look at video's 6 and 7 regarding "blade basics" and "master pages"
https://laracasts.com/series/laravel-from-scratch

Blade template not showing section

I have these three blade templates
In my controller I'm calling dashboard view like this:
View::make('layouts.dashboard');
master.blade.php
<?= stylesheet_link_tag() ?>
<?= javascript_include_tag() ?>
<html>
<body class="fixed">
<div class="wrapper">
<div class="leftside">
#yield('leftside', 'left-side content')
</div>
<div class="rightside">
#yield('rightside', 'right-side content')
</div>
</div>
</body>
dashboard.blade.php
#extends('layouts.master')
#section('leftside')
#yield('sidebar', 'sidebar content')
#stop
sidebar.blade.php
#extends('layouts.dashboard')
#section('sidebar')
aaa
#stop
The dasbhoard blade shows properly in master blade, but sidebar blade doesn't want to show. Does anyone know what i'm doing wrong?
Thank your very much for any help :)
I don't think you can use yield() on a blade template that is not called.
Basically what you can do is make your master.blade.php into this
<html>
<body class="fixed">
<div class="wrapper">
<div class="leftside">
#include('sidebar') {{-- This is sidebar.blade.php --}}
</div>
<div class="rightside">
#include('dashboard') {{-- This is dashboard.blade.php --}}
</div>
</div>
</body>
</html>
Then, assuming that your are calling the dashboard.blade.php template, with both blade templates included. You can use the sections on either master.blade, or sidebar.blade inside dashboard.blade
#extends('layouts.master')
{{-- You can define now the sections available on master.blade and dashbard.blade --}}
OK I found out what was wrong :)
I called View::make('layouts.dashboard') instead of View::make('layouts.sidebar');

how to create separate blade for menu , content , sidebar and footer

my html code is
<html>
<head>
</head>
<body>
<div id="content">
<div id="menu"></div>
<div id="container"></div>
<div id="sidebar"></div>
<div id="footer"></div>
<div>
</body>
</html>
master.blade.php is
<html>
<head>
#yield('title')
#yield('css')
#yield('js')
</head>
<body>
<div id="content">
<div id="container"></div>
<div>
</body>
</html>
menu.blade.php is
<div id="menu"></div>
sidebar.blade.php is
<div id="sidebar"></div>
footer.blade.php is
<div id="footer"></div>
my view file is home.blade.php
#extends('layouts.master')
#section('title')
<title>:: Login ::</title>
#stop
#section('js')
#stop
#extends('layouts.menu')
#extends('layouts.sidebar')
#extends('layouts.footer')
router.php
Route::get('home', array('uses' => 'HomeController#home'));
HomeController.php is
public function home()
{
return View::make('home');
}
id i run
localhost/project/public/index.php/home
it shows only master blade file content , y sidebar , footer and menu not showing , what is the mistake.
Create a your layout #including your menu:
<html>
<head>
<title>#yield('title')</title>
#yield('css')
#yield('js')
</head>
<body>
<div id="content">
<div id="container">
#include('menu')
#yield('content')
</div>
</body>
</html>
Your menu:
<div id="menu">
<ul>
<li>
Item 1
</li>
<li>
Item 2
</li>
<li>
Item 3
</li>
</ul>
</div>
And your view:
#extends('layouts.master')
#section('title')
:: Login ::
#stop
#section('content')
This is your content!
#stop

laravel template inside template

I'm trying to include a template (widget.blade.php) inside a template (master.blade.php) as below. both templates use sections named 'content' but the widget output uses the content from the master instead of the widget content.
master.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>
#section('title')
#show
</title>
</head>
<body>
<div>
#section('content')
#show
</div>
<div>
#section('sidebar')
#show
</div>
</body>
</html>
widget.blade.php
<div class="widget">
#section('content')
#show
</div>
index.blade.php
#extends('master')
#section('content')
Main Content
#stop
#section('sidebar')
#include('mywidget')
#stop
mywidget.blade.php
#extends('widget')
#section('content')
My Widget Content
#stop
The final result
Main Content
Main Content
Any ideas how to fix this collision?
This could be fixed by using #overwrite instead of #stop
#extends('widget')
#section('content')
My Widget Content
#overwrite
source:
http://laravel.com/docs/templates#other-blade-control-structures

Categories